Помогите написать программу распараллеливания быстрой сортровки используя fork() Программу без fork-ов реализовал. а вот с fork проблема.
Вот код
| Код | #include <stdio.h> #include <stdlib.h> #include <unistd>
void QuickSort ( int A[], int from, int to );
int main() { int n,*a,t; printf ("How much: "); scanf("%d", &n); a=(int *)malloc(sizeof(int)*n); if (a==NULL) return 0;
for (t=0;t<n;t++) { printf ("Element: "); scanf("%d", &a[t]); }; QuickSort(a,0,n-1);
for (t=0;t<n;t++) printf("%d ", a[t]);
return 0; }
void QuickSort ( int A[], int from, int to ) { int x, i, j, temp; if ( from >= to ) return; //условное окончание рекурсии i = from; j = to; x = A[(from+to)/2]; //ишем средний елемент while ( i <= j ) { while ( A[i] < x ) i ++; // ишем пару while ( A[j] > x ) j --; // для перестановки if ( i <= j ) { temp = A[i]; A[i] = A[j]; A[j] = temp; //переставляем елементы i ++; //двигаемся j --; //дальше } } QuickSort ( A, from, j );// передаём в потомка QuickSort ( A, i, to ); // передаём в родителя }
|
|