The page shows an animation about the quick sort algorithm.
You can click on the button Animation to play the process.
QuickSort uses a divide and conquer strategy to divide a list into two sub-lists. It is another typical application of divide-and-conquer in sorting algorithms. Ordering n items needs (nlogn) comparisons in the most cases.
Algorithm code:
int partion(int a[],int start,int end){
int i=start,j=end;
int temp=a[start];
while(i<j){
while(i<j && a[j]>=temp) j--;
a[i]=a[j]; // i are more
while(i<j && a[i]<=temp) i++;
a[j]=a[i]; // j are more
}
a[i]=temp; // at end , i=j
return i;
}
void Qsort(int a[],int start,int end){
if(start<end){
int d=partion(a,start,end);
Qsort(a,start,d);
Qsort(a,d+1,end);
}
}
Subscribe
Login
0 Comments