Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void qsort(int v[] , int start , int end)
- {
- int i,last;
- if(start>=end)
- {
- return ; //exit
- }
- Swap( v , start , (start+end)/2);
- last= start; //last==start==0;
- for(i=start+1;i<=end;i++)
- {
- if(v[i]<v[start]) //elements less than pivot coming left ,grater than pivot right the pivot
- {
- Swap(v, ++start, i);
- }
- }
- printf("\n");
- Swap(v, start , last);
- qsort(v,start, last-1); //recursive call for the segment left of the partition index
- qsort(v,last+1, end); //recursive call for the segment right of the partition index
- }
- void Swap(int v[],int i,int j)
- {
- int temp;
- temp=v[i];
- v[i]=v[j];
- v[j]=temp;
- }
- int main()
- {
- int n,i;
- printf("Display your Array size\n");
- scanf("%d",&n);
- int v[n];
- printf("display your array elements \n\n");
- for(i=0;i<n;i++)
- {
- scanf("%d",&v[i]);
- }
- i=0;
- qsort(v, i, n-1);
- printf("Observe your sorting array . it's working very well !!!, isn't it??\n\n");
- for(i=0;i<n;i++)
- {
- printf("%d ",v[i]);
- }
- printf("\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement