算法分析与设计

开发工具Dev-C++

1、插入排序:

 1 #include<stdio.h>
 2 void InsertionSort(int* p,int length){
 3     int i=1,key=p[0],j;
 4     for(;i<length;i++){
 5         key=p[i];
 6         j=i-1;
 7         while(j>=0&&p[j]>key){
 8             p[j+1]=p[j];
 9             j--;
10         }
11         p[j+1]=key;
12     }
13 }
14 int main(){
15     int sort[]={1,5,2,10,23,89};
16     InsertionSort(sort,sizeof(sort)/sizeof(sort[0]));
17     int i=0;
18     while(i<sizeof(sort)/sizeof(sort[0]))
19         printf("%d\t",sort[i++]);
20     return 0;
21 } 
View Code

猜你喜欢

转载自www.cnblogs.com/jakejian/p/9751078.html
今日推荐