Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[100];
- int pivot1(int st, int dr)
- {
- if(st==dr)
- return st;
- else
- {
- if(a[st]>a[dr])
- {
- swap(a[st], a[dr]);
- return pivot1(st, dr-1);
- }
- else
- return pivot1(st+1, dr);
- }
- }
- int pivot(int st, int dr)
- {
- int i=st, j=dr, di=0, dj=1;
- while(i<j)
- {
- if(a[i]>a[j])
- {
- swap(a[i], a[j]);
- swap(di,dj);
- }
- i+=di;
- j-=dj;
- }
- return i;
- }
- void quicksort(int st, int dr)
- {
- if(st<dr)
- {
- int p=pivot(st,dr);
- quicksort(st, p-1);
- quicksort(p+1, dr);
- }
- }
- int main()
- {
- int n, i;
- cin>>n;
- for(i=1; i<=n; i++)
- cin>>a[i];
- pivot(1, n);
- quicksort(1,n);
- for(i=1; i<=n; i++)
- cout<<a[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement