I implemented a bubble sort solution for pset3-sort. It works when I call the function from a test file I made, but when I print out the values of values
in find.c
it gets printed out unsorted.
I've been into this now for two days and just can't seem to understand where I'm going wrong as it works fine in the test file I made which calls and passes the exact same values find.c
does.
Here's my code section for reference:
void sort(int values[], int n)
{
int swapped = true;
while (swapped == true)
{
swapped = false;
for (int i = 0; i < n - 1; i++)
{
if (values[i] > values[i+1])
{
int temp = values[i+1];
values[i+1] = values[i];
values[i] = temp;
swapped = true;
}
}
}
}
Any help would be much appreciated!