当前位置:网站首页>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;
}
}
}
}
边栏推荐
- Live broadcast Preview: integration of JD cloud Devops and jfrog product library
- 365天挑战LeetCode1000题——Day 036 二叉树剪枝 + 子数组和排序后的区间和 + 删除最短的子数组使剩余数组有序
- 抢先预约 | 阿里云无影云应用线上发布会预约开启
- 365天挑战LeetCode1000题——Day 041 二分查找完结纪念 + 第 N 个神奇数字 + 在线选举
- 京东云金秋上云特惠进行中!扫码参与活动
- 携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
- Time complexity and space complexity
- EXIT中断详解
- How to get command parameters in Visual Basic.Net
- WDDM learning
猜你喜欢

Helm chart for Kubernetes

QML control: combobox

Alibaba cloud architect Liang Xu: MES on cloud box helps customers quickly build digital factories

365 day challenge leetcode 1000 questions - day 041 two point search completion anniversary + nth magic number + online election

osg3.6.5编译freetype失败

321,京东言犀×NLPCC 2022挑战赛开赛!

In depth analysis of common cross end technology stacks of app

阿里云架构师细说游戏行业九大趋势

365天挑战LeetCode1000题——Day 040 设计跳表 + 避免洪水泛滥 + 查找大小为 M 的最新分组 + 销售价值减少的颜色球

QT series - Installation
随机推荐
容器安全开源检测工具--问脉 VeinMind(镜像后门、恶意样本、敏感信息、弱口令等)
The road to success in R & D efficiency of 1000 person Internet companies
存储类别
CMU15-213 Shell Lab实验记录
研发效能生态完整图谱&DevOps工具选型必看
OCCT学习002-----环境搭建
CryEngine技术
终端shell常用命令
The latest tank battle 2022 full development notes-1
Is Huatai Securities an AA level securities company? How about this company? Is it safe to open an account?
Unity3d - the object is too far away to see
Alibaba cloud architect Liang Xu: MES on cloud box helps customers quickly build digital factories
C语言 N皇后问题
研发效能|Kubernetes核心技术剖析和DevOps落地经验
365天挑战LeetCode1000题——Day 041 二分查找完结纪念 + 第 N 个神奇数字 + 在线选举
什么是_GLIBCXX_VISIBILITY(default)
直播预告|如何通过“智能边缘安全”提升企业免疫力?
C语言数组入门到精通(数组精讲)
QML control: combobox
Rimworld通过SteamCMD上传创意工坊的方法