diff --git a/gnome-sort.c b/gnome-sort.c index 0bf4fe6..e045810 100644 --- a/gnome-sort.c +++ b/gnome-sort.c @@ -1,19 +1,12 @@ #include -void swap(int a, int b) { - int t = a; - a = b; - b = t; -} +#define SWAP(x, y, T) do { T SWAP = x; x = y; y = SWAP; } while (0) void gnome_sort(int array[], int n) { int i = 0; while (i < n) { if (array[i] > array[i+1]) { - //swap(array[i+1], array[i]); - int t = array[i]; - array[i] = array[i+1]; - array[i+1] = t; + SWAP(array[i], array[i+1], int); if (i > 0) i--; } else i++;