您的位置:首页 > 其它

冒泡排序的实现

2009-01-01 16:53 162 查看
#include<iostream>
using namespace std;
#define N 10
void BubbleSort(int array[])
{
static int sum=0;
int temp=0;
bool bo=true;
int i=0;
while(i<10&&bo){
bo=false;
for(int s=0;s<10;s++){
cout<<array[s]<<" ";
}
cout<<endl;
for(int j=i+1;j<10;j++)
{
if(array[i]<array[j]){
temp=array[i];
array[i]=array[j];
array[j]=temp;
bo=true;
sum++;
i++;
}
}
}
cout<<"共发生的交换次数:"<<sum<<endl;

}
int main(){
//int array[10]={88,99,7,12,25,34,45,62,102,64};
int i=0;
int array
;
for(i;i<N;i++)
array[i]=rand();
cout<<"各次排序结果(包括第一次):"<<endl;
BubbleSort(array);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: