一般的排序方法C++

来源:互联网 发布:深蓝软件 编辑:程序博客网 时间:2024/06/06 02:07

/*project 4-1
Demonstrate the Bubble sort
*/
#include<iostream.h>
#include<cstdlib.h>
using namespace std;

int main()
{
 int nums[10];
 int a,b,t;
 int size;
 size=10;
 for(t=0;t<size;t++)
  nums[t]=rand();
 cout<<"original array is:/n";
 for(t=0;t<size;t++)
  cout<<nums[t]<<' ';
 cout<<'/n';
 //This is the bubble sort
 for(a=1;a<size;a++)
  for(b=size-1;b>=a;b--){
   if(nums[b-1]>nums[b]){
    t=nums[b-1];
    nums[b-1]=nums[b];
    nums[b]=t;
   }
  }
  //display sorted array