Important alert: (current site time 5/24/2013 6:53:07 AM EDT) Brand new: recommended reading for every programming language on the site | revamped discussion board | 7 Source Code CDs

# Quick Sort

Email
 Submitted on: 9/5/2012 12:26:21 PM By: Puneet Jindal Level: Advanced User Rating: Unrated Compatibility: C++ (general), UNIX C++ Views: 1460

Simple implementation of Quick sort algorithm.

code:
Can't Copy and Paste this?
 Terms of Agreement:    By using this code, you agree to the following terms...    You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.    You may link to this code from another website, but ONLY if it is not wrapped in a frame.  You will abide by any additional copyright restrictions which the author may have placed in the code or code's description. ``` //************************************** // Name: Quick Sort // Description:Simple implementation of Quick sort algorithm. // By: Puneet Jindal // //This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=13841&lngWId=3//for details.//************************************** #include 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<

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)