I am trying to understand C by going through K & R. I find it difficult to understand this code for the two functions found in the book:
void qsort(int v[], int left, int right){ int i, last; void swap(int v[], int i, int j); if (left >= right) return; swap(v, left, (left+right)/2); last = left; for ( i = left+1; i<=right; i++) if (v[i]<v[left]) swap(v,++last, i); swap(v,left,last); qsort(v,left,last-1); qsort(v,last+1,right); } void swap(int v[], int i, int j){ int temp; temp = v[i]; v[i] = v[j]; v[j] = temp; }
These two functions perform quicksort for the given array. In the main function, I created an int array and called qsort. It is configured and works great. My question is why the prototype for swap () is placed in qsort () function, and not before main ()?
c prototype
user485498
source share