Advertisement
fahimakber

Untitled

Jul 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. int pivot(int a[],int left,int right);
  4. void sort(int a[],int left,int right);
  5.  
  6. int main()
  7. {
  8.  
  9. int i,limit;
  10. printf ("How many number's you want to insert: ");
  11. scanf("%d",&limit);
  12. int a[limit];
  13. printf ("\nEnter the array value: ");
  14. for(i=0;i<limit;i++)
  15. scanf("%d",&a[i]);
  16. sort(a,0,limit-1);
  17.  
  18. for(i=0;i<limit;i++)
  19. printf("%d",a[i]);
  20.  
  21. printf("\n");
  22. return 0;
  23.  
  24.  
  25. }
  26. int pivot(int a[],int left,int right)
  27. {
  28. int piv =a[right];
  29. int wall;
  30. int i,j;
  31. wall = left-1;
  32. for(j=left;j<=right-1 ;j++)
  33. {
  34. if(a[j]<=piv)
  35. {
  36. wall++;
  37. int temp;
  38. temp=a[j];
  39. a[j]=a[wall];
  40. a[wall]=temp;
  41.  
  42.  
  43. }
  44. }
  45. int temp;
  46. temp=a[wall+1];
  47. a[wall+1]=a[right];
  48. a[right]=temp;
  49.  
  50. return wall+1;
  51.  
  52. }
  53. void sort(int a[],int left,int right)
  54. {
  55. if(left<right)
  56. {
  57. int piv = pivot(a,left,right);
  58. sort(a,left,piv-1);
  59. sort(a,piv+1,right);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement