1 #include<iostream> 2 using namespace std; 3 //冒泡排序 4 void BubbleSort(int a[], int n) 5 { 6 int i, j, t; 7 for (i = 0; i < n; i++) 8 { 9 for (j = n - 1; j >= i+1; j--) 10 { 11 if (a[j] < a[j - 1])//【< 升序】.......【>降序】 12 { 13 t = a[j]; 14 a[j] = a[j - 1]; 15 a[j - 1] = t; 16 } 17 } 18 } 19 } 20 int main() 21 { 22 int a[10]; 23 for (int i = 0; i < 10; i++) 24 cin >> a[i]; 25 for (auto t : a) 26 cout << t << " "; 27 cout << endl; 28 BubbleSort(a, 10);// 冒泡排序 29 for (auto t : a) 30 cout << t << " "; 31 cout << endl; 32 system("pause"); 33 return 0; 34 }