#include<iostream> using namespace std; #include<string> #include<ctime> int main() { //冒泡排序法 int arr[10] = { 3,5,6,4,2,9,8,1,7,0 }; cout << "排序前的数组为:" << endl; for (int i = 0; i < 10; i++) { cout << arr[i] << " "; } cout << endl; for (int j = 0; j <= 9; j++) { for (int i = 0; i < 9-j; i++) { int max = arr[i]; if (arr[i] > arr[i + 1]) { arr[i] = arr[i + 1]; arr[i + 1] = max; } } cout << "第" << j + 1 << "轮排序后的数组为:" << endl; for (int n = 0; n < 10; n++) { cout << arr[n] << " "; } cout << endl; } cout << "排序后的数组为:" << endl; for (int i = 0; i < 10; i++) { cout << arr[i] << " "; } cout << endl; system("pause"); return 0; }