冒泡排序

#include<iostream>
using namespace std;
const int Maxsize=10;
int list[Maxsize];
void bubblesort(int list[],int n)
{
int i,j,tag=1,x;
for(i=n-1;i>0&&tag;i--)
{
tag
=0;
for(j=0;j<i;j++)
if(list[j]>list[j+1])
{
x
=list[j];list[j]=list[j+1];list[j+1]=x;tag=1;
}
}
}
void main()
{
int n;
cin
>>n;
for(int i=0;i<n;i++)cin>>list[i];
bubblesort(list,n);
for(int i=0;i<n;i++)cout<<list[i]<<" ";cout<<endl;
}

  

posted on 2011-08-22 15:10  sysu_mjc  阅读(109)  评论(0编辑  收藏  举报

导航