下载此文档

冒泡排序C++.doc


文档分类:行业资料 | 页数:约2页 举报非法文档有奖
1/2
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/2 下载此文档
文档列表 文档介绍
#include <iostream>
#include<>
using namespace std;
void BubbleSort(int a[],int n)
{
bool flag;
for(int i=0; i<n-1; i++)
{
flag=false;
for(int j=n-1; j>i; j--)
{
if(a[j-1]>a[j])
{
int temp;
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
flag=true;
cout<<endl;
for(int i=0; i<10; i++)
{
cout<<a[i]<<" ";
}
}
if(flag==false) return ;
}
}
int main()
{
int a[10];
for(int i=0; i<10; i++)
{
a[i]=rand()%30;
}
for(int i=0; i<10; i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
BubbleSort(a,10);cout<<endl;
for(int i=0; i<10; i++)
{
cout<<a[i]<<" ";
}
return 0;
}

冒泡排序C++ 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数2
  • 收藏数0 收藏
  • 顶次数0
  • 上传人zbfc1172
  • 文件大小0 KB
  • 时间2015-10-27