Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void Swap(int Element[], constint i, constint j)
- {
- Int temp = Element[i];
- Element[i] = Element[j];
- Element[j] = temp;
- }
- int Partition(int Element[], const int low, const int high)
- {
- Int pivotloc, i;
- Int pivotkey;
- pivotkey = Element[low];
- pivotloc = low;
- for (i = low + 1; i <= high; i++)
- if (Element[i] < pivotkey)
- Swap(Element,++pivotloc, i);
- Swap(Element,low, pivotloc);
- return pivotloc;
- }
- void QuickSort(int Element[],const int low, const int high)
- {
- int pivotloc;
- if (low<high)
- {
- pivotloc = Partition(Element,low, high);
- QuickSort(Element,low, pivotloc - 1);
- QuickSort(Element,pivotloc + 1, high);
- }
- }
- void PRINT(int A[], int n)
- {
- for (int i = 0; i<n; i++)
- {
- cout<< A[i] <<endl;
- }
- }
- void main()
- {
- int A[]={24,13,6,75,9,63,19,29,8,1,5,76,82,11,55,45,60,50,32,25};
- int brE = 20;
- cout<<"Unsorted array:"<<endl;
- PRINT(A, brE);
- QuickSort(A,0,19);
- cout<<endl<<"Sorted array"<<endl;
- PRINT(A, brE);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement