Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void quicksort(int a[],int low,int high);
- int partiation(int a[],int low,int high);
- int main()
- {
- int a[]={4,6,8,3,5,2,0,15};
- int i,l=sizeof(a)/sizeof(a[0]);
- quicksort(a,0,l-1);
- for(i=0;i<l;i++)
- {
- cout<<a[i]<<endl;
- }
- }
- void quicksort(int a[],int low,int high)
- {
- if(low<high)
- {
- int pi=partiation(a,low,high);
- quicksort(a,low,pi-1);
- quicksort(a,pi+1,high);
- }
- }
- int partiation(int a[],int low,int high)
- {
- int pivot=a[high];
- int i=low-1,j;
- for(j=low;j<high;j++)
- {
- if(a[j]<=pivot)
- {
- i++;
- swap(a[i],a[j]);
- }
- }
- swap(a[i+1],a[high]);
- return (i+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment