UNKNOWN //************************************** // Name: Quick Sort // Description:Simple implementation of Quick sort algorithm. // By: Puneet Jindal // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. //Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.13841/lngWId.3/qx/vb/scripts/ShowCode.htm //for details. //************************************** #include<iostream> using namespace std; void Swap(int &a, int &b) { int temp = a; a = b; b = temp; } int Partition(int *arr, int p , int q) { int pivot_index = p; int i = p; int j = p + 1; // Checks for shorter element than pivot element while(j <= q) { while(j <= q && arr[j] > arr[pivot_index]) ++j; if(j <= q && arr[pivot_index] > arr[j]) { swap(arr[i+1],arr[j]); ++i; ++j; } } swap(arr[i],arr[pivot_index]); return i; } void qSort(int *arr, int p, int q) { if(p < q) { int i = Partition(arr,p,q); qSort(arr,p,i); qSort(arr,i+1,q); } } int main() { int arr[] = {90, 80, 100, 70, 110, 60}; qSort(arr,0,5); for(int i = 0 ; i < 6 ; ++i) cout<<arr[i]<<" "; cout<<endl; return 0; }