当前位置:网站首页>Bubble sort
Bubble sort
2022-06-12 21:05:00 【Bald and weak】
thought :
Traverse the array in turn to determine the largest number and put it in the last digit , A total of n Trip to , Make sure that the maximum number in each trip is placed at the end .
Code :
void BubbleSort(int* arr, int len) {
bool flag = true;// Used to determine whether to enter the exchange loop
for (int i = 0; i < len; i++) {
for (int j = 0; j < len - i; j++) {
if (arr[j] > arr[j + 1]) {
flag = false;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
if (flag == true)// Not entering the cycle Prove that there is no exchange , It's an ordered sequence
break;
}}
int main()
{
int arr[] = { 4,1,3,8 };
BubbleSort(arr, sizeof(arr)/sizeof(arr[0]));
return 0;
}
边栏推荐
- 新品发布丨竣达智能综合环境监测终端
- 中小型机房动力环境综合监控解决方案
- The salted fish has been transmitted for 5W times, and the latest spring recruit face-to-face test questions of bytes have been leaked
- Cv2.lut() (populates the output array with values from the lookup table)
- leetcode:210. 课程表 II
- #113 Path Sum II
- remote: Support for password authentication was removed on August 13, 2021
- #141 Linked List Cycle
- Circularly insert one excel column and the sum of multiple columns
- GPU giant NVIDIA suffered a "devastating" network attack, and the number one malware shut down its botnet infrastructure | global network security hotspot on February 28
猜你喜欢

shell语言

torch. nn. Linear() function

Lintcode:127. Topology sorting

Teambition 协作应用心得分享|社区征文

lintcode:127 · 拓扑排序

leetcode:210. 課程錶 II

Nexus3 build local warehouse
![Li Mu [practical machine learning] 1.4 data annotation](/img/e4/2593b1dec04476a9cc3b4af94dc189.jpg)
Li Mu [practical machine learning] 1.4 data annotation

Lombok package is successfully installed, but the runtime prompts that get, set method and constructor solution cannot be found

Composer version degradation
随机推荐
atoi超强解析
HR SaaS unicorn is about to emerge. Will the employee experience be the next explosive point?
Pytorch how to set random number seed to make the result repeatable
结构体知识点all in
Successful transition from self-study test halfway, 10K for the first test
#141 Linked List Cycle
String Basics
lintcode:127 · 拓扑排序
金融信创爆发年!袋鼠云数栈DTinsight全线产品通过信通院信创专项测试
In the spring recruitment of 2022, the test engineer will have a full set of interview strategies to thoroughly understand all the technical stacks (all dry goods)
Data visualization - histogram
一级指针&二级指针知识点梳理
指针与数组&指针与const&结构体与const
#141 Linked List Cycle
Integrated monitoring solution for power environment of small and medium-sized computer rooms
Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer
Gather function in pytorch_
nn. PReLU(planes)
Leetcode: 210. Programme II
Li Mu [practical machine learning] 1.4 data annotation