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