Cawa245

Untitled

Dec 15th, 2020 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <omp.h>
  3. #include <iostream>
  4. #include <chrono>
  5. #include <vector>
  6. #include <random>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. void quicksort(int* arr, int n) {
  12.  
  13.     long i = 0, j = n - 1;
  14.     int pivot = arr[n / 2];
  15.     do {
  16.         while (arr[i] < pivot) i++;
  17.         while (arr[j] > pivot) j--;
  18.         if (i <= j) {
  19.             swap(arr[i], arr[j]);
  20.             i++;
  21.             j--;
  22.         }
  23.     } while (i <= j);
  24.  
  25. #pragma omp task shared(arr) firstprivate(i,j)
  26.     if (j > 0) quicksort(arr, j + 1);
  27.  
  28. #pragma omp task shared(arr) firstprivate(i,j)
  29.     if(n>i) quicksort(arr+i,n-1);
  30. #pragma omp taskwait
  31.  
  32. }
  33.  
  34. int Alg() {
  35.     long const n = 10;
  36.     int arr[n];
  37.     for (auto i = 0; i < n; i++) {
  38.         arr[i] = rand() % 10;
  39.     }
  40.     quicksort(arr, n);
  41.     for(auto i=0;i<n;i++) cout<<arr[i]<<endl;
  42.     return 0;
  43. }
  44.  
  45.  
  46.  
Add Comment
Please, Sign In to add comment