当前位置:网站首页>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;} 边栏推荐
猜你喜欢

DataStream API(基础篇) 完整使用 (第五章)

2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day

Vivado时序约束中Tcl命令的对象及属性

关于判断单峰数组的几种方法

【API Management】What is API Management and why is it important?

DAY25: Logic vulnerability recurrence

【API架构】REST API 行业辩论:OData vs GraphQL vs ORDS

1 活动时间与安排

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~

00后女孩月薪3200,3年买两套房,这个程序员变现新风口千万要把握住
随机推荐
【企业架构】敏捷与企业架构:战略联盟
13 【script setup 总结】
【数据库架构】OLTP 和 OLAP:实际比较
【元宇宙欧米说】听兔迷兔如何从虚拟到现实创造潮玩新时代
对称加密与非对称加密的区别
Linux下载安装MySql
【数据架构】分布式数据网格作为集中式数据单体的解决方案
关于镜像源的一些记录
07 【动态组件 组件注册】
Optimistic and pessimistic locking
DAY25:逻辑漏洞
PTA Exercise 2.2 Rotate an Array Left
00后女孩月薪3200,3年买两套房,这个程序员变现新风口千万要把握住
A File Online Query Display and Download Function Realized by Delphi
FPGA时钟篇(三) MRCC和SRCC的区别
shell------常用小工具,sort,uniq,tr,cut
js-----数组转换成树形结构
不要把公司当成家,被通知裁员时会变得不幸...
MUDA:对齐特定域的分布和分类器以实现来自多源域的跨域分类
浅析JWT安全问题