1 #include<iostream> 2 using namespace std; 3 4 int direct_sort(int n,int array[100]){//直接插入排序 5 register int i,temp; 6 for(i=1;i<n;i++){ 7 temp=array[i]; 8 int j=i-1; 9 while(array[j]>temp){ 10 array[j+1]=array[j]; 11 j--; 12 } 13 array[j+1]=temp; 14 } 15 return 0; 16 } 17 18 int print(int n,int array[100]){ 19 int i; 20 for(i=0;i<n;i++){ 21 cout<<array[i]<<" "; 22 } 23 cout<<endl; 24 return 0; 25 } 26 int main() 27 { 28 int array[10]={5,7,8,2,3,5,4,3,2,1}; 29 direct_sort(10,array); 30 print(10,array); 31 return 0; 32 }