- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int n[6] = {8, -95, 321, 5, 0, -18};
- cout << "排序前: ";
- for (int g = 0; g < 6; g++) {
- cout << n[g] << " ";
- }
- cout << endl;
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 5 - i; j++) {
- if (n[j] > n[j + 1]) {
- int temp = n[j];
- n[j] = n[j + 1];
- n[j + 1] = temp;
- }
- }
- }
- cout << "排序後: ";
- for (int g = 0; g < 6; g++) {
- cout << n[g] << " ";
- }
- cout << endl;
- return 0;
- }
複製代碼 |