当前位置:网站首页>重学冒泡排序
重学冒泡排序
2022-08-10 09:15:00 【dudu-03】
冒泡排序是我们开始学习编程时候就已经学会的算法,今天来将之前学过的算法重写一下。
index是我们下一次循环所到的尾部。
#include<bits/stdc++.h>
using namespace std;
void so(int a[])
{
int index = 10;
int j;
int co = 1;
bool flag = true;
for(int i = 0; i < 10; i++) cin >> a[i];
while(flag){
j = -1;
for(int i = 0; i < index; i++){
if(a[i] > a[i + 1]) {
swap(a[i],a[i + 1]);
j = i + 1;
cout << "第" << co++ << "次排序:";
for(int i = 0; i < 10; i++) cout << a[i] << " " ;
puts("");
}
if(i == index - 1) index = j;
}
if(j == -1){
flag = !flag;
cout << "排序完成";
}
}
}
int main()
{
int a[100];
so(a);
return 0;
}
边栏推荐
猜你喜欢
[Metaverse Omi Says] See how UCOUCO integrates performance art into the Metaverse
J9数字科普:Web 3.0 是关于数据所有权还是去中心化?
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
06 【生命周期 模板引用】
ARM Architecture 2: Processor Core and Assembly Instruction Set
【 WeChat applet 】 read page navigation
2022-08-09 第六小组 瞒春 学习笔记
【微信小程序】一文读懂页面导航
UGUI - Events, iTween Plugin
J9 Digital Theory: What kind of sparks will Web3.0+ Internet e-commerce cause?
随机推荐
关于镜像源的一些记录
keepalived:双主配置
硬件工程师90天学习资料及笔记汇总
jq封装树形下拉选择框组件
dayjs-----time format
Spotify使用C4模型表达其架构设计
07 【动态组件 组件注册】
[Metaverse Omi Says] See how UCOUCO integrates performance art into the Metaverse
【 WeChat applet 】 read page navigation
CAD转WPF: 关于CAD图纸文件转换为WPF矢量代码文件(xaml文件)的技巧
shell------常用小工具,sort,uniq,tr,cut
js reads excel time format conversion
不要把公司当成家,被通知裁员时会变得不幸...
ShardingSphere入门
navicat导入SQL文件报:[ERR] 2006 - MySQL server has gone away [ERR] -- MySQL dump 10.13 Distrib 5.7.34
初识Flink 完整使用 (第一章)
[OAuth2] Nineteen, OpenID Connect dynamic client registration
Pieces of TensorFlow 2.9 (1)
J9 Number Theory: Macro Analysis of DAO Characteristics
用高质量图像标注数据加速AI商业化落地