|
用c实现的插入排序法
用c实现的插入排序法,先输入10个数,然后利用插入排序法进行排序,将结果输出。算法简单,可供初学者学习。 #i nclude "stdio.h" #i nclude "conio.h" main() { int a[10],r[11]; int *p; int i,j; for(i=0;i<10;i++) { p=&a[i]; printf("please scan the NO: %d\n",i); scanf("%d",p); r[i+1]=a[i]; } r[0]=1; for(i=2;i<=10;i++) { r[0]=r[i]; j=i-1; while(r[j]>r[0]) { r[j+1]=r[j]; j--; } r[j+1]=r[0]; } for(i=1;i<=10;i++) {p=&r[i];printf("form min to max the NO: %d value=%d\n",i,*p);} getch(); }
|