#include
using namespace std;
void bubble(int l [],int n){//
使用中间变量temp实现互换
int i,temp,exchange=n,j;
while(exchange){
j=exchange;
exchange=0;
for(i=0;i<j;i++){
if(l[i]>l[i+1]){
temp=l[i];
l[i]=l[i+1];
l[i+1]=temp;
exchange=i+1;
}
}
}
}
void bubble2(int l [],int n){//
不借助中间变量
int i,exchange=n,j;
while(exchange){
j=exchange;
exchange=0;
for(i=0;i<j;i++){
if(l[i]>l[i+1]){
l[i]=l[i]+l[i+1];
l[i+1]=l[i]-l[i+1];
l[i]=l[i]-l[i+1];
exchange=i+1;
}
}
}
}
int main(){
int link[10];
cout<<“input ten number”<<endl;
for(int i=0;i<10;i++){
cin>>link[i];
}
//bubble(link,10);
bubble2(link,10);
for(int j=0;j<10;j++){
cout<<link[j]<<endl;
}
return 0;
}