无题
2015-11-08 15:54
239 查看
#include <stdio.h> #define N 20 void Insert(int a[],int n,int x); int main() { int a[N+1]; int x,i,n; printf("Input array size :"); scanf("%d",&n); printf("Input array:"); for (int i = 0; i < n; ++i) { scanf("%d",&a[i]); /* code */ } printf("Input x:"); scanf("%d",&x); Insert(a,n,x); printf("After insert %d :\n",x); for (int i = 0; i < n+1; ++i) { /* code */ printf("%4d",a[i]); } printf("\n"); return 0; } void Insert(int a[],int n,int x) { int i=0,pos; while(i<n&&x>a[i]) { i++; } pos = i; for (int i = n-1; i >= pos; i--) { /* code */ a[i+1] = a[i]; } a[pos] = x; }
相关文章推荐
- Ubuntu Golang环境搭建
- oracle10g 和11g
- Mybatis中resultMap和resultType
- Paxos算法与Zookeeper分析
- androdi studio之aidl文件生成
- IO流之Properties(配置文件)
- 典型用户和场景(家长老陈和小石头)
- 精益生产
- Zookeeper与paxos算法
- NumPy-快速处理数据--ufunc运算--广播--ufunc方法
- 信息安全系统设计基础第九周学习总结
- Problem A. Dynamic Grid
- [JS] IE下ajax请求不生效或者请求结果不更新
- win+R的快捷方式
- 单一职责原则(Single Responsibility Principle SRP)
- Unity5 AssetBundle 打包以及加载
- windows下weblogic单双向ssl设置
- 教你透彻了解红黑树
- android应用1之计算器
- hdu4935 Prime Tree(2014多校联合第七场)