当前位置:网站首页>冒泡排序 C语言
冒泡排序 C语言
2022-07-29 05:09:00 【卷饼85】
冒泡排序 C语言
初始冒泡排序
//冒泡排序
void bubbleSort(int* arr, int arrSize)//数组 数组长度
{
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;
}
}
}
}
优化
方法:加个值判断是否有必要继续排序
如果判断值为真,说明进行了排序
如果判断值为假,说明已经排序完毕,不需要再进行排序
void bubbleSort(int* arr, int arrSize)//冒泡排序(优化)
{
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;
}
}
}
}
边栏推荐
- 阿里云张新涛:异构计算为数字经济提供澎湃动力
- 京东云联合Forrester咨询发布混合云报告 云原生成为驱动产业发展新引擎
- During the appointment, the 2022 JD cloud industrial integration new product launch was launched online
- 最新坦克大战2022-全程开发笔记-1
- 6.3 references
- Custom QML control: imagebutton
- Live broadcast Preview: integration of JD cloud Devops and jfrog product library
- OCCT学习002-----环境搭建
- CryEngine技术
- The latest tank battle 2022 - Notes on the whole development -2
猜你喜欢

CMU15-213 Malloc Lab实验记录

Rimworld通过SteamCMD上传创意工坊的方法

Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team

CMU15-213 Shell Lab实验记录

365天挑战LeetCode1000题——Day 041 二分查找完结纪念 + 第 N 个神奇数字 + 在线选举

ARFoundation入门教程7-url动态加载图像跟踪库

OCCT学习001-----简介

Scikit learn -- steps and understanding of machine learning application development

容器安全开源检测工具--问脉 VeinMind(镜像后门、恶意样本、敏感信息、弱口令等)

C语言数组入门到精通(数组精讲)
随机推荐
自定义Qml控件:ImageButton
MFC集成qt验证及问题处理
This article takes you to understand the implementation of surround notification @around and final notification @after
OCCT学习001-----简介
千人规模互联网公司研发效能成功之路
小白高薪捷径-Qt开发游戏—贪吃蛇
QML control: combobox
6.3 references
C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
AI应用第一课:C语言支付宝刷脸登录
osg3.6.5编译freetype失败
Why is Google's internal tools not suitable for you?
串口通讯部分详解
CMU15-213 Shell Lab实验记录
vim编辑器使用
水一篇图的拓扑排序
[event preview] cloud development, efficient and intelligent - the second Alibaba cloud ECS cloudbuild developer competition is about to start
CMake 设置vs启动运行环境路径
研发效能|Kubernetes核心技术剖析和DevOps落地经验
SM integration is as simple as before, and the steps are clear (detailed)