Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void QuickSort(int L, int R, int *p){
- int i,j,x;
- i=L;
- j=R;
- x=p[(i+j)/2];
- while(i<=j){
- while(p[i]<x) ++i;
- while(p[j]>x) --j;
- if(i<=j){
- swap(p[i],p[j]);
- i++;
- j--;
- }
- }
- if(i<R)
- QuickSort(i,R,p);
- if(j>L)
- QuickSort(L,j,p);
- }
- int main() {
- int n;
- cin>>n;
- int *mas=new int [n];
- for(int i=0; i<n; ++i)
- cin>>mas[i];
- QuickSort(0,n-1,mas);
- for(int i=0; i<n; ++i)
- cout<<mas[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement