Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. void swap(int &x,int &y)
  3. {
  4. int t=x;
  5. x=y;
  6. y=t;
  7. }
  8. int partition(int x[],int low, int high)
  9. {
  10. int pivot = x[high],i=low,j=high-1;
  11. while(i<j)
  12. {
  13. while(x[i]<pivot)
  14. i++;
  15. while(x[j]>pivot)
  16. j--;
  17. if(i>=j)
  18. break;
  19. swap(x[i],x[j]);
  20. }
  21. swap(x[j+1],x[high]);
  22. return j+1;
  23. }
  24. void QuickSort(int x[],int low,int high)
  25. {
  26. if(!(low<high))
  27. return;
  28. else
  29. {
  30. int p=partition(x,low,high);
  31. for(int i=0;i<15;i++)
  32. std::cout<<x[i]<<' ';
  33. std::cout<<std::endl;
  34. QuickSort(x,low,p-1);
  35. QuickSort(x,p+1,high);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement