Advertisement
juyana

quick sort

Apr 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void quick(int A[],int n,int beg,int end,int loc)
  5. {
  6. int left=beg;
  7. int right=end;
  8. loc=beg;
  9. while(A[loc]<=A[right]&&loc!=right)
  10. {
  11. right=right-1;
  12. }
  13. if(loc==right)
  14. return;
  15. if(A[loc]>a[right])
  16. {
  17. int t=a[loc];
  18. A[loc]=A[right];
  19. A[right]=t;
  20. loc=right;
  21. }
  22. while(A[left]<=A[loc]&&left!=loc)
  23. {
  24. left++;
  25.  
  26. }
  27. if(loc==left)
  28. return;
  29. if(A[left]>A[loc])
  30. {
  31. temp=A[loc];
  32. A[loc]=A[left];
  33. A[left]=temp;
  34.  
  35. }
  36. }
  37.  
  38. int main()
  39. {
  40. int n,A[100],lower[100],upper[100];
  41.  
  42. cin>>n;
  43. for(int i=0;i<n;i++)
  44. {
  45. cin>>A[i];
  46.  
  47. }
  48. int top=0,beg,en,loc,end;
  49. if(n>1)
  50. {
  51. top=top+1;
  52. lower[top]=1;
  53. upper[top]=n;
  54.  
  55. }
  56. while(top!=NULL)
  57. {
  58. beg=lower[top];
  59. end=upper[top];
  60. top=top-1;
  61. loc=1;
  62. quick(A,n,beg,end,loc);
  63. if(beg<loc-1)
  64. {
  65. top++;
  66. lower[top]=beg;
  67. upper[top]=loc=1;
  68. }
  69. if()
  70. {
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement