I was having a small problem in understanding the command swap
Plz look at this quick sort program
It uses the middle element of each subarray for partitioning
/* 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 fewer than 2 elements*/
swap (v, left, (left + right)/2; /*Move partition element to v*/
last = left;
for (i = left + 1; i <= right; i++) /*partition*/
if (v[i] < v[left])
swap (v, ++last,i); /* Shouldn't it be v*/
swap (v,left,last); /* restore partition element*/
qsort(v, last + 1, right);
O.K..this program is from page #87
of the Ernighan and Ritchie book for 'C' programming
WHat I am wondering is what is the term 'j' in the program. It has never been initialized.
and secondly could any one tell me what does v and v mean in context with the above program.
I mean v is an array i.e. v, so how could it simply be used as 'v'.
while being used in the swap command.
What does the swap(v,++last ,i); mean exactly