Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int Partition(int* A,int p,int r)
- {
- int x=A[r];
- int i=p-1;
- for(int j=p;j<r-1;j++)
- {
- if(A[j]<=x)
- {
- i=i+1;
- swap(A[i],A[j]);
- cout<<"x"<<endl;
- }
- }
- swap(A[i+1],A[r]);
- return i+1;
- }
- void Quick(int * A,int p,int r)
- {
- if(p<r)
- {
- int q=Partition(A,p,r);
- Quick(A,p,q-1);
- Quick(A,q+1,r);
- }
- }
- int main()
- {
- int A[]={20,30,10,40,50,5,100,80};
- int z=sizeof(A)/sizeof(A[0]);
- for(int i=0;i<z;i++)
- cout<<A[i]<<",";
- cout<<endl;
- //cout<<z<<endl;
- Quick(A,0,z-1);
- cout<<z<<endl;
- for(int i=0;i<z;i++)
- cout<<A[i]<<",";
- cout<<endl;
- //cout<<sizeof(A)/sizeof(A[0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement