I am working on a sorting program that generates a list of random numbers and does a sort. I have run across some programs in an old C book. In the bubble sort it doesn't seem to work. Since I am not a programmer just a college student I am having trouble finding the problem with this program. I know the program needs modified to generate random numbers but haven't gotten that far yet. Anybody see the problem with this program?
Bubble Sort
#include <stdio.h>
void sort (int [],int);
void print_it (int [], int);
int main(void)
{
int doit[] = {4, 6, 8, 2, 4, 1, 9, 23, 99, 77, 55, 33, 11}; /* Can replace this with the random generated numbers*/
int size;
size = sizeof(doit) / sizeof(int);
sort (doit, size – 1);
print_it(doit, size);
}
void sort (int array[], int limit)
{
int row, column, temp, sorted;
for (row = 0, row <= limit; row++)
{
sorted = 0;
for (column = 0, column <= limit – 1 ; column++)
{
if (array[column] > array[column + 1])
{
sorted = 1;
temp = array[column];
array[column] = array[column + 1];
array[column + 1] = temp;
}
}
if (sorted = = 0)
break;
}
}
void print_it (int doit[], int limit)
{
int I;
(for (i = 0; i < limit; i++)
{
printf(“%4i”, doit[i]);
if (((i + 1) % 14) = = 0) putchar (‘\n’);
}
putchar(‘\n’)
}