Research Article
A New Look at Worst Case Complexity: A Statistical Approach
Algorithm 2
The “C” code implementation of the naive (first element pivot) quick sort.
// System Specification: as given in main text | int main (int argc, char *argv) | { | ⋯⋯⋯⋯⋯⋯⋯ | quicksort( A, low, high); | ⋯⋯⋯⋯⋯⋯⋯ | } | quicksort(int A, int low, int high) | { | int p; | if(low>=high) | return; | p=partition(A,low,high); | quicksort(A,low,p-1); | quicksort(A,p+1,high); | } | int partition(int A, int low, int high) | { | int temp,key,i,j; | key = Alow; | i=low+1; | j=high; | while(i <= j) | { | while(Ai <= key && i<=j) | { | i++; | } | while(Aj > key && i <= j) | { | j- -; | } | if(i <= j) | { | temp=Ai; | Ai=Aj; | Aj=temp; | } | } | Alow=Aj; | Aj=key; | return(j); | } |
|