Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. /*void sortarr(int a[], int t)
  8. {
  9.     int l;
  10.     for (int j=0; j<t; j++)
  11.     {
  12.         for(int k=j+1; k<=t ; k++)
  13.         {
  14.             if(a[j]>a[k])
  15.             {
  16.                 l=a[k];
  17.                 a[k]=a[j];
  18.                 a[j]=l;
  19.             }
  20.         }
  21.     }
  22. }*/
  23.  
  24.  
  25.  
  26. void quickSort(int arr[], int left, int right) {
  27.  
  28.       int i = left, j = right;
  29.  
  30.       int tmp;
  31.  
  32.       int pivot = arr[(left + right) / 2];
  33.  
  34.  
  35.  
  36.       /* partition */
  37.  
  38.       while (i <= j) {
  39.  
  40.             while (arr[i] < pivot)
  41.  
  42.                   i++;
  43.  
  44.             while (arr[j] > pivot)
  45.  
  46.                   j--;
  47.  
  48.             if (i <= j) {
  49.  
  50.                   swap(arr[i], arr[j]);
  51.  
  52.                   i++;
  53.  
  54.                   j--;
  55.  
  56.             }
  57.  
  58.       };
  59.  
  60.  
  61.  
  62.       /* recursion */
  63.  
  64.       if (left < j)
  65.  
  66.             quickSort(arr, left, j);
  67.  
  68.       if (i < right)
  69.  
  70.             quickSort(arr, i, right);
  71.  
  72. }
  73.  
  74. int main()
  75. {
  76.     int t;
  77.     int x[50];
  78.  
  79.     cin >> t;
  80.  
  81.     for(int i=0;i<t;i++)
  82.     {
  83.         cin >> x[i];
  84.     }
  85.  
  86.     //sortarr(x,t);
  87.  
  88.     for(int c=0;c<t;c++)
  89.     {
  90.         cout << x[c] << endl;
  91.     }
  92.  
  93.     quickSort(x,x[0],x[t-1]);
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement