标签:
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 }
标签:
原文地址:http://www.cnblogs.com/lhyz/p/4305440.html