Bubble-sort Source-Code
November 27th, 2007
#include
#include
#define NUM_ITEMS 1000
void bubbleSort(int numbers[], int array_size);
int numbers[NUM_ITEMS];
int counter;
int main()
{
srand(getpid()); //fill array with random integers
for (i = 0; i < NUM_ITEMS; i++)
numbers[i] = rand();
bubbleSort(numbers, NUM_ITEMS); //perform bubble sort on array
for (i = 0; i < NUM_ITEMS; i++)
printf(”%i\n”, numbers[i]);
printf(”Done with sort.\n”);
printf(”%i %i\n”, i, counter);
}
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
for (i = (array_size - 1); i >= 0; i–)
{
for (j = 1; j <= i; j++)
{
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
counter++;
}
counter++;
}
}
Inlinks :
- Apa itu Algorithms?
- Bubble-sort Source-Code
- Data Security
- Enkripsi RC4 part 2
- Heap-sort Source-Code
- Insertion-sort Source-Code
- Keamanan Informasi dan Kriptografi
- LINEAR DISCRIMINANT ANALYSIS (LDA)
- Matrix-Chain-Multiply Source-Code
- Matrix-Chain-Order
- MD5 and SHA-1 ( Hash Function Chryptography )
- Merge-sort Source-Code
- Quick-sort Source-Code
- Sejarah Kriptografi
- Selection-sort Source-Code
- SORTING ALGORITHM #1
- SORTING ALGORITHM ANALYSIS






