Guest User

Untitled

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