--- a/sort.c +++ b/sort.c @@ -27,7 +27,12 @@ void swap (int *v, int i, int j) { - int old = v[i]; + int old; + + if (i == j) + return; + + old = v[i]; v[i] = v[j]; v[j] = old;