#25145: sort c++


conanhuang8382 (conan)

學校 : 慧燈中學
編號 : 145576
來源 : [59.124.158.45]
最後登入時間 :
2021-11-05 12:20:23
a104. 排序 -- yoooooooo | From: [114.136.62.94] | 發表日期 : 2021-04-23 23:28

#include <bits/stdc++.h>

using namespace std;

 

void sort (int num[], int n){

int b;

for (int m = 1; m <= n; m++){

for (int i = 1; i <= n - 1; i++){

if (num[i] > num[i + 1]){

b = num[i];

num[i] = num[i + 1];

num[i + 1] = b;

}

}

}

 

 

}

int main(){

int num[1001], n = 0;

while (cin >> n){

for (int i = 1; i <= n; i++){

cin >> num[i];

}

sort(num, n);

for (int i = 1; i <= n; i++){

cout << num[i] << " ";

}

cout << endl;

}

 

}

 
ZeroJudge Forum