Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <pthread.h>
- typedef struct abc{
- int *A;
- int n;
- }abc ;
- void *swap( void* G){
- abc *ABC = (abc*) G;
- int temp;
- if(ABC->A[ABC->n] > ABC->A[ABC->n + 1]){
- temp = ABC->A[ABC->n];
- ABC->A[ABC->n] = ABC->A[ABC->n + 1];
- ABC->A[ABC->n + 1] = temp;
- }
- return 0;
- }
- void oddEvenTransSort(int *A, int n){
- int m = n/2;
- pthread_t *T;
- abc *temp;
- T = new pthread_t [m];
- for (int k = 1; k < n; ++k) {
- if(k%2==0) {
- for (int i = 0; i < n; i += 2) {
- temp->A=A;
- temp->n=n;
- pthread_create(&(T[i]), NULL, swap, temp);
- }
- for(int i = 0 ; i < n ; i+=2)
- {
- pthread_join(T[i] , NULL);
- }
- }
- else{
- for (int i = 1; i < n; i += 2) {
- temp->A=A;
- temp->n=n;
- pthread_create(&(T[i]), NULL, swap, temp);
- }
- for(int i = 0 ; i < n ; i+=2)
- {
- pthread_join(T[i] , NULL);
- }
- }
- }
- }
- int main(){
- int n;
- std::cout<<"enter array size";
- std::cin>>n;
- int A[n];
- std::cout<<"enter array";
- for (int i = 0; i < n; ++i) {
- std::cin>>A[i];
- }
- oddEvenTransSort(A, n);
- for (int j = 0; j < n; ++j) {
- std::cout<<A[j];
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment