⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maopao2.cpp

📁 数据结构算法VC++实现
💻 CPP
字号:
//冒泡排序法(上浮)maopao2.cpp
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<time.h>
#define N 10
void gensort(int b[],int n)
{int i,j;
 for(i=0;i<n-1;i++)
  {for(j=i+1;j<n;j++)
    if(b[i]>b[j])
     {int temp=b[i];
      b[i]=b[j];b[j]=temp;}
   for(int k=0;k<n;k++)
    cout<<setw(4)<<b[k];
   cout<<endl;
  }
}
void main()
{cout<<"maopao2.cpp运行结果:\n";
 int ai[N],i;
 srand(time(0));
 for(i=0;i<N;i++)
  ai[i]=rand()%100;
 cout<<"排序前数组:\n";
 for(i=0;i<N;i++)
  cout<<setw(4)<<ai[i];
 cout<<endl;
 cout<<"排序过程演示:\n";
 gensort(ai,sizeof(ai)/sizeof(int));
 cout<<"排序后数组:\n";
 for(i=0;i<N;i++)
  cout<<setw(4)<<ai[i];
 cout<<endl;cin.get();}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -