#include <iostream>
using namespace std;
void Bubblesort(int t_a[],int n){
int bound=n,exchange=n; //bound为 下次循环取到得的边界值
int temp; //exchange为最后一次交换的值,这个值即下次循环为边界
while(exchange!=0){ //若exchange为0,则说明没有发生交换
bound=exchange;
exchange=0; //交换开始前置0 ,若没交换则依然为0
for(int i=0;i<bound;i++){
if (t_a[i]>t_a[i+1]){
temp=t_a[i];
t_a[i]=t_a[i+1];
t_a[i+1]=temp;
exchange=i;
}
}
}
}
int main(){
int n;
cin>>n;
int a[10];
for(int i=0;i<n;i++){
cin>>a[i];
}cout<<"排序前:";
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
Bubblesort(a, n);cout<<"排序后:";
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
IMG_20190722_213230.jpg