Guest User

Untitled

a guest
May 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <pthread.h>
  3.  
  4.  
  5. void *swap( abc ABC){
  6.  
  7.  
  8.      int temp;
  9.      if(ABC.A[ABC.n] > ABC.A[ABC.n + 1]){
  10.          temp = ABC.A[ABC.n];
  11.          ABC.A[ABC.n] = ABC.A[ABC.n + 1];
  12.          ABC.A[ABC.n + 1] = temp;
  13.      }
  14.  
  15. }
  16. void oddEvenTransSort(int *A, int n){
  17.     int m = n/2;
  18.     pthread_t *T;
  19.     abc temp;
  20.     T = new pthread_t [m];
  21.     for (int k = 1; k < n; ++k) {
  22.  
  23.         if(k%2==0) {
  24.             for (int i = 0; i < n; i += 2) {
  25.                 temp.A=A;
  26.                 temp.n=n;
  27.                 pthread_create(&(T[i]), NULL, swap, &temp);
  28.             }
  29.             for(int i = 0 ; i < n ; i+=2)
  30.             {
  31.                 pthread_join(T[i] , NULL);
  32.             }
  33.         }
  34.     }
  35.  
  36. }
  37.  
  38. int main(){
  39.  
  40.     int n;
  41.     std::cout<<"enter array size";
  42.     std::cin>>n;
  43.     int A[n];
  44.     std::cout<<"enter array";
  45.     for (int i = 0; i < n; ++i) {
  46.         std::cin>>A[i];
  47.     }
  48.     //bubbleSort(A, n);
  49.     for (int j = 0; j < n; ++j) {
  50.         std::cout<<A[j];
  51.     }
  52.  
  53.     return 0;
  54. }
Add Comment
Please, Sign In to add comment