码迷,mamicode.com
首页 > 编程语言 > 详细

C++插入排序实现

时间:2014-09-17 23:16:12      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   div   

bubuko.com,布布扣
 1 # include<iostream>
 2 # include<cstdio>
 3 using namespace std;
 4 void Insert(int *_piArr,int len)
 5 {
 6     int i = 1;
 7     for(;i < len;i++)
 8     {
 9         int j = i;
10         int x = _piArr[i];
11         while((j > 0)&&(_piArr[j-1]>x))//前一个大于后一个
12         {
13             _piArr[j] = _piArr[j-1];
14             j--;//向后移动
15         }
16         _piArr[j] = x;//
17     }
18 }
19 int main()
20 {
21     int a[100],n;
22     cin>>n;
23     for(int i = 0;i < n;i++)
24     {
25         cin>>a[i];
26     }
27     Insert(a,n);
28     for(int i = 0;i < n;i++)
29     {
30         cout<<a[i]<<" ";
31     }
32 }
View Code

 

C++插入排序实现

标签:style   blog   http   color   io   os   ar   for   div   

原文地址:http://www.cnblogs.com/sxmcACM/p/3978168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!