Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- void swap(int &x,int &y)
- {
- int t=x;
- x=y;
- y=t;
- }
- int partition(int x[],int low, int high)
- {
- int pivot = x[high],i=low,j=high-1;
- while(i<j)
- {
- while(x[i]<pivot)
- i++;
- while(x[j]>pivot)
- j--;
- if(i>=j)
- break;
- swap(x[i],x[j]);
- }
- swap(x[j+1],x[high]);
- return j+1;
- }
- void QuickSort(int x[],int low,int high)
- {
- if(!(low<high))
- return;
- else
- {
- int p=partition(x,low,high);
- for(int i=0;i<15;i++)
- std::cout<<x[i]<<' ';
- std::cout<<std::endl;
- QuickSort(x,low,p-1);
- QuickSort(x,p+1,high);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement