插入排序
来源:互联网 发布:淘宝网购物商城首页 编辑:程序博客网 时间:2024/06/06 02:56
原理很简单,直接看代码:
#include<iostream>#include<cstdio> #include<algorithm>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;const int maxn = 100 + 10;int a[maxn];int n;void solve(){for(int i = 1; i <= n; i ++){int x = a[i];int j = i - 1;while(j >= 1 && a[j] > x){a[j + 1] = a[j];j --;}a[j + 1] = x;}}int main(){while( ~ scanf("%d",&n)){for(int i = 1; i <= n; i ++){scanf("%d",&a[i]);}solve();for(int i = 1; i <= n; i ++)cout << a[i] << " ";cout <<endl; }return 0;}
0 0
- 插入排序-【插入排序】
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- Ubuntu+linux:Ubuntu14.04下安装和使用git
- leetcode二叉树问题合集
- 3. Hibernate_HelloWorld 详解
- Android Webview后退
- iOS开发之字典(NSDictionary)和JSON字符串(NSString)之间互转
- 插入排序
- android File 转成 byte[]
- 9、Linux正则表达式基础
- Linux下不可不知的文件类型及表示颜色
- C++ set
- 云计算基础概念
- 像余额的单位转换
- 二叉树的最大深度
- windows10上搭建tensorflow简易教程