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

插入排序

时间:2017-02-27 23:15:07      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:sort   --   size   ace   int   ima   src   space   color   

 1 #include<iostream>
 2 using namespace std;
 3 
 4 
 5 void Insertion_Sort(int a[],int n)
 6 {
 7     if (n == 1)
 8         exit(1);
 9     for (int k = 1; k < n; k++)
10     {
11         int x = a[k];
12         int j = k - 1;
13         while (j >= 0 && a[j] > x)
14         {
15             a[j + 1] = a[j];
16             j--;
17         }
18         a[j + 1] = x;
19     }
20 }
21 
22 
23 void main()
24 {
25     int a[10];
26     for (int i = 0; i < 10; i++)
27         a[i] = 10 - i;
28     int n=sizeof(a) / sizeof(int);
29     Insertion_Sort(a, n);
30     for (int i = 0; i < 10; i++)
31         cout << a[i] << endl;
32 }

技术分享

 

插入排序

标签:sort   --   size   ace   int   ima   src   space   color   

原文地址:http://www.cnblogs.com/zhengzhe/p/6476745.html

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