当前位置:网站首页>重学冒泡排序
重学冒泡排序
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;
}
边栏推荐
- The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
- 2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day
- 13 【script setup 总结】
- js reads excel time format conversion
- 乐观锁与悲观锁
- 04 【计算属性 侦听器】
- Unity—UGUI control
- 【API Management】What is API Management and why is it important?
- npm i安装报错
- PTA Exercise 2.2 Rotate an Array Left
猜你喜欢
BUUCTF【pwn】解题记录(4-6页持续更新中)
Basic concepts, structures, and classes of thread pools
CTFSHOW七夕杯web
ARM Architecture 3: Addressing and Exception Handling of ARM Instructions
原型和原型链
多线程知识点总结之温故而知新
PTA Exercise 2.2 Rotate an Array Left
DAY25:逻辑漏洞复现
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality
英伟达游戏显卡营收暴跌/ 谷歌数据中心爆炸致3人受伤/ iPhone电量百分比回归…今日更多新鲜事在此...
随机推荐
06 【生命周期 模板引用】
UE4 粒子特效基础学习 (01-将粒子效果挂载到角色身上)
SQL优化总结
CTFSHOW七夕杯web
jq封装树形下拉选择框组件
推荐几个高质量的软件测试实战项目
【API Management】What is API Management and why is it important?
速卖通卖家如何抓住产品搜索权重
Vivado时序约束中Tcl命令的对象及属性
【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
【数据库架构】OLTP 和 OLAP:实际比较
1499. 满足不等式的最大值 堆/双端队列
Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference
I don't want to do accounting anymore, Die changed to a new one, moved forward bravely, and finally successfully passed the career change test to double his monthly salary~
2 模块一:科研思维培养
浅析JWT安全问题
FPGA时钟篇(一) 7系列的时钟结构
DAY25: Logic Vulnerability
对称加密与非对称加密的区别
并查集学习