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

插入排序-algorithms_3th

时间:2015-02-28 16:00:03      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include <iostream>
 2 #include <iterator>
 3 using namespace std;
 4 
 5 void displayArray(int* const,int&);
 6 
 7 void INSERTION_SORT(int * const A,int &length){
 8     int key;
 9     int i;
10     for (int j = 1; j < length; ++j){
11         key = A[j];
12         i = j - 1;
13         while (i>=0 && key < A[i]){
14             A[i + 1] = A[i];
15             --i;
16         }
17         A[i + 1] = key;
18     }
19     displayArray(A, length);
20 }
21 
22 void displayArray(int * const a,int &length){
23     for (int i = 0; i < length; ++i){
24         cout << " " << a[i];
25     }
26     cout << endl;
27 }
28 
29 int main(void)
30 {
31     int a[] = {5,2,4,6,1,3};
32     int length = end(a) - begin(a);
33     INSERTION_SORT(a, length);
34     system("pause");
35     return 0;
36 }

 

插入排序-algorithms_3th

标签:

原文地址:http://www.cnblogs.com/lhyz/p/4305406.html

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