Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int pivot(int a[],int left,int right);
- void sort(int a[],int left,int right);
- int main()
- {
- int i,limit;
- printf ("How many number's you want to insert: ");
- scanf("%d",&limit);
- int a[limit];
- printf ("\nEnter the array value: ");
- for(i=0;i<limit;i++)
- scanf("%d",&a[i]);
- sort(a,0,limit-1);
- for(i=0;i<limit;i++)
- printf("%d",a[i]);
- printf("\n");
- return 0;
- }
- int pivot(int a[],int left,int right)
- {
- int piv =a[right];
- int wall;
- int i,j;
- wall = left-1;
- for(j=left;j<=right-1 ;j++)
- {
- if(a[j]<=piv)
- {
- wall++;
- int temp;
- temp=a[j];
- a[j]=a[wall];
- a[wall]=temp;
- }
- }
- int temp;
- temp=a[wall+1];
- a[wall+1]=a[right];
- a[right]=temp;
- return wall+1;
- }
- void sort(int a[],int left,int right)
- {
- if(left<right)
- {
- int piv = pivot(a,left,right);
- sort(a,left,piv-1);
- sort(a,piv+1,right);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement