1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /*quick sort*/ #include<stdio.h> void quicksort(int x[5],int,int); int main(){ int x[10],i; printf("Please Enter elements to Sort MAX 10 nn"); for(i=0;i<=9;i++) scanf("%d",&x[i]); quicksort(x,0,9); printf("Sorted elements: n"); for(i=0;i<=9;i++) printf(" %d",x[i]); getch(); } void quicksort(int x[5],int first,int last){ int pivot,j,temp,i,n; if(first<last){ pivot=first; i=first; j=last; while(i<j){ while(x[i]<=x[pivot]&&i<last) i++; while(x[j]>x[pivot]) j--; if(i<j){ temp=x[i]; x[i]=x[j]; x[j]=temp; } } temp=x[pivot]; x[pivot]=x[j]; x[j]=temp; quicksort(x,first,j-1); quicksort(x,j+1,last); } } |