插入排序
来源:互联网 发布:树莓派3 linux 编辑:程序博客网 时间:2024/05/14 12:46
#include <iostream>using namespace std;void insert_sort(int a[],int);const maxn=1000;int main(){int a[maxn];int n,i;cin>>n;for (i=0;i<n;i++)cin>>a[i];insert_sort(a,n);for (i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;return 0;}//插入排序(小到大)void insert_sort(int a[],int n){int i,j,key;for (i=1;i<n;i++){key=a[i];//插入的数j=i-1;//下标while (j>=0 && a[j]>key){a[j+1]=a[j];//当找到比key大的数时,这些较大的数向后移动 j--;}a[j+1]=key;//插入key}}
0 0
- 插入排序-【插入排序】
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 插入排序
- 新年搬新家
- WEP协议加密解密过程详解
- Android异步任务处理
- ASCII编码和Unicode编码
- 递归太深会导致栈溢出
- 插入排序
- HDU 1028 Ignatius and the Princess III(母函数)
- 【设计模式】不就是换DB嘛——抽象工厂
- [Android]Ultra-Pull-To-Refresh之listview下拉刷新、上拉加载的用例-已更新
- openflow协议各版本下载(1.0/1.1/1.2/1.3/1.4/1.5)
- 一般前后台技术的优化
- 309. Best Time to Buy and Sell Stock with Cooldown LeetCode
- woj1034 hdu1290 Cut the Apple 数学题
- 互联网电商高并发解决方案(一)