#include<iostream>
using namespace std;
int main()
{
void Bubble_Sort(int array[],int n);
cout<<"Please input data number is:";
int n,i,*p;
cin>>n;
p=new int [n+1];
for(i=1;i<n+1;i++)
cin>>p[i];
Bubble_Sort(p,n);
for(i=1;i<n+1;i++)
cout<<p[i]<<" ";
cout<<endl;
return 0;
}
void Bubble_Sort(int array[],int n)
{
int exchange=n,s,i;
while(exchange)
{
s=exchange;
exchange=0;
for(i=1;i<s;i++)
{
if(array[i]>array[i+1])
{
array[0]=array[i];
array[i]=array[i+1];
array[i+1]=array[0];
exchange=i;
}
}
}
}
c++实现起泡排序
最新推荐文章于 2021-11-17 17:45:10 发布