我写改进型冒泡大家过来看一看,大家给一点建意
程序代码:#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
using namespace std;
int main()
{
srand((time(0)));
const int M = 20;
int i,j,a[20],temp,m;
bool Bool;
for(i=0;i<M;a[i]=rand()%100+1,i++);
for(i=0;i<M;i++)
cout<<a[i]<<" ";
cout<<'\n';
i=0;
do{
Bool = false;
for(j=i;j<M-1-i;j++)
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
Bool = true;
}
if(Bool == true)
{
Bool = false;
for(m = M-2-i ; m > i; m --)
if( a[m] < a[m-1] )
{
temp = a[m];
a[m] = a[m-1];
a[m-1] = temp;
Bool = true;
}
}
i++;
}while(Bool);
for(i=0;i<M;i++)
cout<<a[i]<<" ";
getch();
return 0;
}有什么建意可以提出来[ 本帖最后由 点线面 于 2011-1-7 09:56 编辑 ]







