This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: //subrange and elements in R will be on the right side of subrange while(l <= r) { //move l to the right unil we find an element that does not belong to L while(l < r && s[r] <x) { l++; //s[r]<=x handles cases where different indexes have equal value } //move r to the left until we find an element that doesn't belong to G while(l<r && s[r]>x) { r; } //if l and r have not crossed eachother, then l and r are indexes of numbers that do not //belong to L or G. We swap them if(l < r) { int tmp = s[l]; s[l] = s[r]; s[r] = tmp; } } //while //now we have L and G. We need to position x in between L and G //swap x w/ the index in l int tmp = s[l]; s[l] = s[right]; s[right] = tmp; //now the pivot is in l. Recur. In L and G quicksortSubrange(s, left, l1); quicksortSubrange(s+1, l+1/*(L+one)*/, right); } //end quicksortSubrange...
View
Full Document
 Fall '08
 Staff
 Sort, Rightwing politics, Leftwing politics, int tmp, int *s, pivot int

Click to edit the document details