I made a bubble sort code, but I want to make sure that my code is correct. My code is
void sort(int values[], int n)
{
if (n == 1) {
return 0;
}
int swapcount = 0;
for (int j = 0; j < n - 1; j++) {
int compare1 = values[i];
int compare2 = values[i + 1];
if (compare1 > compare2) {
swap(compare1, compare2);
i++;
swapcount++;
}
else {
i++;
}
}
if (swapcount == 0) {
return 0;
}
void sort(int values[], int n);
// TODO: implement a sorting algorithm
return;
}
void swap(compare1, compare2) {
int placeholder;
placeholder = compare2;
compare2 = compare1;
compare1 = placeholder;
}