#include <iostream>
#include <string>
using namespace std;
void paixv2(int r[], int a);
void paixv(int r[], int a){
int i, j, t;
for(i=0; i<a-1; i++){
for(j=0; j<a-i-1; j++){
if(r[j]>r[j+1]){
t = r[j];
r[j] = r[j+1];
r[j+1] = t;
}
}
}
for(i=0; i<5; i++){
cout<<r[i];
}
};
void bubblesort(int a[], int n){
int i, j, t;
for (i=0; i<n-1;i++)
for(j=0; j<n-i-1; j++)
if(a[j]>a[j+1]){ //交换两个变量的值
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
cout<<"排序后为: "<<endl;
for (i=0;i<5;i++){
cout<<a[i]<<" ";
}
};
void bubblesort2(int r[],int n)
{
int i;
int bound,exchange=n-1; //bound作为边界 exchange是交换的位置
while(exchange!=0)
{
bound=exchange;
exchange=0;
for(int j=0;j<bound;j++)
if(r[j]>r[j+1])
{
int t=r[j];r[j]=r[j+1];r[j+1]=t;
exchange=j;
}
}
for (i=0;i<5;i++){
cout<<r[i]<<" ";
}
}
void main(){
int a[5];
cout<<"请输入五个数: "<<endl;
cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
int n = 5;
paixv(a,n);
cout<<endl;
paixv2(a, n);
bubblesort(a, n);
bubblesort2(a, n);
int b;
cin>>b;
}
void paixv2(int r[], int a){
int i, j, t, bound, exchange;
exchange = a-1;
while(exchange!=0){
bound = exchange;
exchange = 0;
for(j=0; j<bound; j++){
if(r[j]>r[j+1]){
t = r[j];
r[j] = r[j+1];
r[j+1] = t;
exchange = j;
}
}
}
for(i=0; i<5; i++){
cout<<r[i];
}
}