SHARE
TWEET

Untitled

a guest Jul 17th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(int &a, int &b)
  6. {
  7.     int temp = a;
  8.     a = b;
  9.     b = temp;
  10. }
  11.  
  12. int pivot_pos(int arr[], int low, int high)
  13. {
  14.     int pivot = arr[high];
  15.     int i = (low-1)
  16.  
  17.     for(j = low; j <= high; j++)
  18.     {
  19.         i++;
  20.         if(arr[i]>arr[j])
  21.         {
  22.             swap(arr[i], arr[j]);
  23.         }
  24.     }
  25.     swap(arr[i], arr[high]);
  26.  
  27.     return (i+1);
  28. }
  29.  
  30. void quicksort(int arr[], int low, int high)
  31. {
  32.     if (low < high)
  33.     {
  34.         int pi = pivot_pos(arr, low, high);
  35.         quicksort(arr, pi+1, high);
  36.         quicksort(arr, low, pi-1);
  37.     }
  38. }
  39.  
  40. int main()
  41. {
  42.     int arr[] = {5,23,222,1,21,76,8,5,43,11,56};
  43.     int size = sizeof(arr)/sizeof(arr[0]);
  44.     quicksort(arr, 0, size-1);
  45.  
  46.     system("pause");
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top