I decided to do pset 3 from 2017 as extra practice, but ran into an issue with bubble sort. More specifically, when I run check50 on it I get:
:( sorts {5,4,3,2,1} expected "1", not "\n5\n5\n5\n5\n5..."
and one other comparable error. The other tests check out. I'm defining swaps ahead of the loop too because it won't let me compile otherwise.
// Bubble sort
void sort(int values[], int n)
{
int swaps = 0;
do
{
// Until penultimate element
int swaps = 0;
for (int i = 1; i < n; i++)
{
if (values[i] > values[i + 1])
{
int tmp = values[i];
values[i + 1] = values[i];
values[i] = tmp;
swaps++;
}
}
n--;
}
while (swaps > 0);
return;
}