4 comments:
Patch Set #2, Line 18: static void swap(int *v1, int *v2)
Should this maybe be a macro (using typeof()) in some header to be more widely useful?
Patch Set #2, Line 26: static int is_bigger(int v1, int v2)
This... seems a bit overkill?
Patch Set #2, Line 51: idx = i + 1;
I don't get the point of the idx variable. This is updated on every loop iteration but doesn't actually affect the loop. Why don't you just say len = i at the end (or len-- which would be equivalent)?
Really, this whole function seems to be a very unobvious way to write
for (j = 0; j < num_entries - 1; j++)
for (i = 0; i < num_entries - 1 - j; i++)
Patch Set #2, Line 54: } while (len > 1);
You should include an early abort case for when no swaps were made during a whole outer loop iteration. If we're using bubblesort, we should at least make sure we can benefit from one of its biggest advantages (O(n) on close-to-already-sorted data).
To view, visit change 31544. To unsubscribe, or for help writing mail filters, visit settings.