This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Introduction to Computer Programming October 2, 2008 CSC180 Fall 2008, University of Toronto Quicksort • The quicksort algorithm was developed by Hoare in 1962. • Use a partition element to divide an unsorted array into two subsets. • All elements in subset one are less than the partition element. • All elements in subset two are greater than or equal to the partition element. • The following code uses the middle element as the partition element. • An implementation of the quicksort algorithm using recursion: CSC180 Fall 2008, University of Toronto 1 /* quicksort.c */ /* interchange v[i] and v[j] */ void swap(int v, int i, int j) { int temp; temp = v[i]; v[i] = v[j]; v[j] = temp; } /* sort v[left]...v[right] into increasing order */ void qsort(int v, int left, int right) { int i, last; 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++)...
View
Full Document
 Fall '01
 na
 C Programming, Computer Programming, Sort, partition element

Click to edit the document details