bubblesort(冒泡法排序)==C++源代码

来源:互联网 发布:日程安排软件哪个好 编辑:程序博客网 时间:2024/06/16 11:39

//----数学中有乘法口诀。。那只是工具。我们都很熟悉。

//----C++中有一些基本的程序。也只是工具我们必须像熟悉乘法口诀一样去熟悉这些程序。

//----很基础的一些东西必须熟练。。。

 

//-======这些程序写的很粗糙。。。如果想用,请将其做进一步完善与修改。。。。

#include<iostream>    
using namespace std;
int main()
{
 void bubblesort(int a[],int n);
 int a[10];
 cout<<" input 10 numbers :"<<endl;
 for(int i=0;i<10;i++)
  cin>>a[i];
 cout<<endl;
 bubblesort(a,10);
 cout<<" the  sorted numbers:"<<endl;
 for( i=0;i<10;i++)
  cout<<a[i]<<" ";
 cout<<endl;
 return 0;
}
void bubblesort(int a[],int n)  //---  一维数组做参数
{
 int t;
 for(int j=0;j<9;j++)
  for(inti=0;i<9-j;i++) 
   if(a[i]>a[i+1])      //------找出最大的数,让他下沉。。。。。。。。。。。
   {
    t=a[i];
    a[i]=a[i+1];
    a[i+1]=t;
   }
}

 

 

 

 

bubblesort(冒泡法排序)==C++源代码
原创粉丝点击