当前位置:网站首页>Bubble sort c language
Bubble sort c language
2022-07-29 05:27:00 【Tortilla 85】
Bubble sort C Language
Initial bubble sort
// Bubble sort
void bubbleSort(int* arr, int arrSize)// Array The length of the array
{
int i, j;
for (i = 0; i < arrSize; i++)
{
if (!b){
break; }
for (j = 0;j<arrSize-i-1;j++)
{
int temp;
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
Optimize
Method : Add a value to judge whether it is necessary to continue sorting
If the judgment value is true , Instructions are sorted
If the judgment value is false , Description has been sorted , No more sorting
void bubbleSort(int* arr, int arrSize)// Bubble sort ( Optimize )
{
int i, j;
bool b = true;
for (i = 0; i < arrSize; i++)
{
if (!b){
break; }
b = false;
for (j = 0;j<arrSize-i-1;j++)
{
int temp;
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
b = true;
}
}
}
}
边栏推荐
- CMU15-213 Shell Lab实验记录
- QtCreator+CMake编译器设置
- Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com
- Xiaolu Inn - Trailer
- 直播预告:京东云DevOps与JFrog制品库的融合
- 副作用和序列点
- Live broadcast preview | how to improve enterprise immunity through "intelligent edge security"?
- 哈夫曼树以及哈夫曼编码在文件压缩上的应用
- Why is Google's internal tools not suitable for you?
- osgSimplegl3结合RenderDoc工具
猜你喜欢

Vs code的安装步骤及环境配置

During the appointment, the 2022 JD cloud industrial integration new product launch was launched online

Live broadcast preview | how to improve enterprise immunity through "intelligent edge security"?

How mongodb inserts, deletes and updates documents

研发效能生态完整图谱&DevOps工具选型必看

200 多家 ISV 入驻!阿里云计算巢发布一周年

osg3.6.5编译freetype失败

OCCT学习003-----MFC单文档工程

01-01-osg GL3 环境搭建

阿里云架构师梁旭:MES on 云盒,助力客户快速构建数字工厂
随机推荐
Cryengine5 shader debugging
How rimworld uploads creative workshops through steamcmd
Database course design of online assistant teaching platform for high school chemistry
最新坦克大战2022-全程开发笔记-2
AI应用第一课:C语言支付宝刷脸登录
MFC集成qt验证及问题处理
365天挑战LeetCode1000题——Day 040 设计跳表 + 避免洪水泛滥 + 查找大小为 M 的最新分组 + 销售价值减少的颜色球
What is_ GLIBCXX_ VISIBILITY(default)
Custom QML control: imagebutton
CMake 设置vs启动运行环境路径
365天挑战LeetCode1000题——Day 036 二叉树剪枝 + 子数组和排序后的区间和 + 删除最短的子数组使剩余数组有序
QtCreator+CMake编译器设置
osg3.6.5编译freetype失败
阿里云张新涛:异构计算为数字经济提供澎湃动力
英伟达周锡健:设计到数字营销的最后一公里
Alibaba cloud architect Liang Xu: MES on cloud box helps customers quickly build digital factories
C how to realize simple factory mode
Li Yan, CEO of parallel cloud: cloudxr, opens the channel to the metauniverse
vim编辑器使用
QML custom tabbar