64,654
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
using namespace std;
void bubble(int a[],int size);
int main()
{
int array[]={12,54,6,5,8,15,45,64,6,6,5};
int len=sizeof(array)/sizeof(int);
for(int i=0;i <len;i++)
cout <<array[i] <<" ";
cout <<endl;
bubble(array,len);
}
void bubble(int a[],int size)
{
for(int i=0;i <size;i++)
for(int j=0;j <size-1;j++)
{
if(a[j+1]>a[j])
{
int temp;
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
for(int k=0;k <size;k++)
cout <<a[k] <<" ";
cout<<endl;
}