当前位置:网站首页>Relearn bubble sort
Relearn bubble sort
2022-08-10 09:20:00 【dudu-03】
Bubble sort is an algorithm that we have learned when we started learning programming. Today, we will rewrite the algorithm we have learned before.
index is the end of our next loop.
#includeusing 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 << "No." << co++ << "Order: ";for(int i = 0; i < 10; i++) cout << a[i] << " " ;puts("");}if(i == index - 1) index = j;}if(j == -1){flag = !flag;cout << "Sort done";}}}int main(){int a[100];so(a);return 0;} 边栏推荐
猜你喜欢

ARM Architecture 2: Processor Core and Assembly Instruction Set

Shell functions and arrays

【搜索引擎】Solr:提高批量索引的性能
![[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality](/img/e8/f431a9c932e0fa5f413b1f7e09bf46.png)
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality

How to break the DeepFake face-changing scam?turn him over

J9数字论:关于DAO 特点的宏观分析

FPGA的虚拟时钟如何使用?

【OAuth2】二十、OAuth2扩展协议 PKCE

不要把公司当成家,被通知裁员时会变得不幸...

UE4 Sequence添加基础动画效果 (04-在序列中使用粒子效果)
随机推荐
微信小程序--》小程序生命周期和WXS使用
js--------对象数组转换成二维数组(excel表格导出)
【元宇宙欧米说】看UCOUCO如何将行为艺术融入元宇宙
【业务架构】价值链分析:提高客户价值和盈利能力
【FAQ】【Push Kit】推送服务,回执配置一直报错、回执过期修改、怎么删除配置的回执
刷题工具h
【搜索引擎】Solr:提高批量索引的性能
keepalived:主备配置
How AliExpress sellers seize product search weight
Static关键字及应用,继承的概念
DAY25: Logic Vulnerability
推荐几个高质量的软件测试实战项目
人
Spotify使用C4模型表达其架构设计
mySQL add, delete, modify and check advanced
navicat导入SQL文件报:[ERR] 2006 - MySQL server has gone away [ERR] -- MySQL dump 10.13 Distrib 5.7.34
13 【script setup 总结】
打工人的第27天-平凡但不平淡的日子
CTFSHOW七夕杯web
Docker搭建Mysql一主一从