直接插入排序
2016-04-12 12:50
375 查看
#include<stdio.h> #include<string.h> #define MAX 200 int R[MAX]; //直接插入排序算法 void Insert_Order(int n) { int i,j; for(i=2;i<=n;i++) { if(R[i]<R[i-1]) { R[0]=R[i]; j=i-1; do{ R[j+1]=R[j]; j--; }while(R[0]<R[j]); } R[j+1]=R[0]; } } int main() { int n; int i; printf("Please input n under %d:\n",MAX); scanf("%d",&n); if(n<1||n>MAX) { printf("Please input n above 1 and below %d\n",MAX); return 0; } printf("Please input the array one by one:"); for(i=1;i<=n;i++) { scanf("%d",&R[i]); } printf("The array you input is :"); for(i=1;i<=n;i++) { printf("%d ",R[i]); } Insert_Order(n); printf("The array after order is:"); for(i=1;i<=n;i++) { printf("%d ",R[i]); } return 0; }
相关文章推荐
- 剑指offer面试题 求数组中连续子数组的最大和
- 短信验证码
- Struts2-Value Stack浅析
- 深度卷积神经网络用于图像缩放Image Scaling using Deep Convolutional Neural Networks
- hihoCoder - 1082 - 然而沼跃鱼早就看穿了一切 (字符串处理!!)
- 完全用Python工作---Harness the power of Python
- HBase学习总结(1)
- Struts详解
- Struts2中访问Servlet API的几种方式
- 2.停止线程
- CodeForces 176A Trading Business(贪心)
- MySQL 入门(七)—— 视图
- 算法训练 友好数
- Mac 可设置环境变量的位置、查看和添加PATH环境变量
- matlab 遍历图像文件夹
- Java中public int length()的用法
- 一行div框,两边顶头显示
- Android M MO SMS/MMS FLOW
- 算法训练 水仙花
- Qt中采用多线程实现Socket编程