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

📄 maopao3.cpp

📁 方便大家使用的c版本 算法
💻 CPP
字号:
//冒泡排序法(下沉)maopao3.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=1;i<n;i++)
 {for(j=0;j<n-i;j++)
   if(b[j]>b[j+1])
    {int temp=b[j];
     b[j]=b[j+1];b[j+1]=temp;}
  for(int k=0;k<n;k++)
   cout<<setw(4)<<b[k];
  cout<<endl;
 }
}
void main()
{cout<<"maopao3.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 + -