【数据结构】——插入排序
插入排序:
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int arry[7] = {49,38,65,97,76,13,27}; 6 7 void show_arry() 8 { 9 int i; 10 for(i = 0; i < 7; i++) 11 printf("%d ",arry[i]); 12 putchar('\n'); 13 } 14 15 void sort() 16 { 17 int i,j; 18 int tmp; 19 for(i = 0; i < 7; i++){ 20 j = i; 21 tmp = arry[i]; 22 while(j > 0 && tmp < arry[j - 1]){ 23 arry[j] = arry[j - 1]; 24 arry[j - 1] = tmp; 25 j--; 26 } 27 } 28 } 29 30 void text() 31 { 32 arry[0] = 0; 33 arry[1] = 1; 34 } 35 36 int main(int argc, char *argv[]) 37 { 38 puts("before sort"); 39 show_arry(); 40 sort(); 41 //text(); 42 puts("after sort"); 43 show_arry(); 44 return 0; 45 }