标签:oid end print 快速排序 break lse main == ret
1 #include<bits/stdc++.h> 2 void quickSort(int a[],int first,int end) 3 { 4 if(first==end) return; 5 int i = first,j = end,temp; 6 while(i<j){ 7 while(i<j&&temp<=a[j]){ 8 j--; 9 } 10 if(i<j){ 11 a[i++] = a[j]; 12 } 13 while(i<j&&temp>=a[i]){ 14 i++; 15 } 16 if(i<j){ 17 a[j--] = a[i]; 18 } 19 } 20 a[i] = temp; 21 quickSort(a,first,i-1); 22 quickSort(a,i+1,end); 23 } 24 int main(){ 25 int arr[100] = { 49, 38, 65, 97, 23, 22, 76, 1, 5, 8, 2, 5, -1, 22 }; 26 int len = 0,i; 27 for(i=0;;i++){ 28 if(arr[i]==0) break; 29 else{ 30 len++; 31 } 32 } 33 printf("%d\n",len); 34 quickSort(arr,0,len-1); 35 for(i=0;i<len;i++){ 36 printf("%d ",arr[i]); 37 } 38 return 0; 39 }
标签:oid end print 快速排序 break lse main == ret
原文地址:https://www.cnblogs.com/cdandcd/p/13844949.html