Advertisement
rotno98

Quick_sort not good

Oct 15th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void Quick(int* A,int ts,int tb,int pivot)
  6. {
  7.  
  8. while(ts>tb)
  9. {
  10.  
  11.  
  12.  
  13. while(A[tb]<=A[pivot])
  14. {
  15. tb++;
  16. }
  17. while(A[ts]>A[pivot])
  18. {
  19. ts--;
  20. }
  21.  
  22. if(tb<ts)
  23. {
  24. swap(A[tb],A[ts]);
  25. }
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32. swap(A[ts],A[pivot]);
  33.  
  34.  
  35.  
  36. }
  37.  
  38. int main()
  39. {
  40.  
  41. int A[]={20,30,10,40,50,5,100,80};
  42. int z=sizeof(A)/sizeof(A[0]);
  43.  
  44. Quick(A,0,z-1,0);
  45.  
  46.  
  47.  
  48. for(int i=0;i<z;i++)
  49. cout<<A[i]<<",";
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement