#include<iostream>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, i, j, t, x, flag = 0;
cin >> n;
int* arr = new int[n];
for (i = 0; i < n; i++)
cin >> arr[i];
for (i = 0; i < n; i++)
{
for (j = n - 1; j > i; j--)
{
if (arr[j] < arr[j - 1])
{
t = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = t;
flag = 1;
}
}
if (flag == 0)
break;
for (x = 0; x < n; x++)
cout << arr[x] << " ";
cout << endl;
flag = 0;
}
delete []arr;
return 0;
}
标签:arr,int,cin,冒泡排序,++,flag From: https://www.cnblogs.com/atrue/p/17347811.html