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

冒泡排序-algorithms_3th

时间:2015-02-28 15:58:02      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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

 

冒泡排序-algorithms_3th

标签:

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

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