トピックの説明
バブル ソートを実装するプログラム。非降順でソートし、テスト データは整数です。
入力
最初の行はソートするデータ要素の数で、 2 行目はソートするデータ要素です。
出力
最初の行は、最初のバブル ソートの結果を出力します。
#include<bits/stdc++.h>
using namespace std;
int a[1005], m;
int main(){
cin>>m;
for(int i = 0; i < m; i++) cin>>a[i];
for(int i = 0; i < m - 1; i++) if(a[i] > a[i+1]) swap(a[i], a[i+1]);
for(int i = 0; i < m; i++ ) cout<<a[i]<<" ";
return 0;
}