0 کاربر و 1 مهمان درحال مشاهده موضوع.
سوال بنظرم مبهمه.حداقل کد برنامه رو بزار
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <sys/ipc.h>#include <sys/shm.h>//functionvoid input(int A[], int n){ int i, num; for(i=1 ; i<=n ; i++) { printf("enter number%d : ", i); scanf("%d", &num); A[i] = num; }}void out(int A[], int n){ int i; printf("--------- sorted is --------- \n"); for(i=1 ; i<=n ; i++) { printf("%d\t", A[i]); } printf("\n");}int partition( int A[], int p, int q){ int temp; int x = A[p]; int i = p; for (int j = p+1; j <= q; j++) { if (A[j] <= x) { i++; temp = A[j]; A[j] = A[i]; A[i] = temp; } } temp = A[i]; A[i] = A[p]; A[p] = temp; return i;}// //quick sortvoid Quick_sort( int A[], int p,int r){ int q; int leftchild = -1; int rightchild = -1; if( p<r) { int status; q = partition(A,p,r); leftchild = fork(); if (leftchild < 0) { perror("fork"); exit(1); } if (leftchild == 0) { Quick_sort( A, p, q-1); exit(0); } else { rightchild = fork(); if (rightchild < 0) { perror("fork"); exit(1); } if (rightchild == 0) { Quick_sort( A, q+1, r); exit(0); } } waitpid(leftchild, &status, 0); waitpid(rightchild, &status, 0); }} int main(){ //one example int n; int A[20] = {0}; printf("how many number you get to sort?"); scanf("%d", &n); input(A, n); Quick_sort(A, 1, n); out(A, n); return 0;}