Quicksort Code?

This code doesnt make any sense. Especially the check on v[i]<v[left]. Shouldnt that be the other way around? According to this video, the code doesnt correspond...


http://www.youtube.com/watch?v=Z5nSXTnD1I4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* qsort: sort v[left]...v[right] into increasing order */
void qsort(int v[], int left, int right)
{
int i, last;
void swap(int v[], int i, int j);
if (left >= right) /* do nothing if array contains */
   return; /* fewer than two elements */
swap(v, left, (left + right)/2); /* move partition elem */
last = left; /* to v[0] */
for (i = left + 1; i <= right; i++) /* partition */
   if (v[i] < v[left])
      swap(v, ++last, i);
swap(v, left, last); /* restore partition elem */
qsort(v, left, last-1);
qsort(v, last+1, right);
}


Topic archived. No new replies allowed.