1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void MyQuickSort(int *pArray,int Start,int End) 5 { 6 int key = pArray[Start]; 7 int low = Start,high = End; 8 while(low < high) 9 { 10 while(low < high && key < pArray[high]) 11 { 12 high--; 13 } 14 pArray[low] = pArray[high]; 15 while(low < high && key > pArray[low]) 16 { 17 low++; 18 } 19 pArray[high] = pArray[low]; 20 } 21 pArray[low] = key; 22 if(Start < low) 23 MyQuickSort(pArray,Start,low); 24 if(End > low+1) 25 MyQuickSort(pArray,low+1,End); 26 } 27 28 int main() 29 { 30 int pArray[20],nCount; 31 while(~scanf("%d",&nCount) && nCount) 32 { 33 for(int i = 0; i<nCount && i<20;i++) 34 { 35 scanf("%d",&pArray[i]); 36 } 37 MyQuickSort(pArray,0,nCount-1); 38 for(int i = 0;i<nCount && i<20;i++) 39 { 40 printf("%d ",pArray[i]); 41 } 42 } 43 44 return 0; 45 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void MyQuickSort(int *pArray,int Start,int End) 5 { 6 int key = pArray[Start]; 7 int low = Start,high = End; 8 while(low < high) 9 { 10 while(low < high && key < pArray[high]) 11 { 12 high--; 13 } 14 pArray[low] = pArray[high]; 15 while(low < high && key > pArray[low]) 16 { 17 low++; 18 } 19 pArray[high] = pArray[low]; 20 } 21 pArray[low] = key; 22 if(Start < low) 23 MyQuickSort(pArray,Start,low); 24 if(End > low+1) 25 MyQuickSort(pArray,low+1,End); 26 } 27 28 int main() 29 { 30 int pArray[20],nCount; 31 while(~scanf("%d",&nCount) && nCount) 32 { 33 for(int i = 0; i<nCount && i<20;i++) 34 { 35 scanf("%d",&pArray[i]); 36 } 37 MyQuickSort(pArray,0,nCount-1); 38 for(int i = 0;i<nCount && i<20;i++) 39 { 40 printf("%d ",pArray[i]); 41 } 42 } 43 44 return 0; 45 }