蓝桥杯省赛无忧 排序 课件40 冒泡排序
发布时间:2024年01月24日

01 冒泡排序的思想

02 冒泡排序的实现

03 例题讲解

#include <iostream>
using namespace std;
void bubbleSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main() {
int n;
cin >> n;
int treasures[n];
for(int i = 0; i < n; i++) {
cin >> treasures[i];
}
bubbleSort(treasures, n);
for(int i = 0; i < n; i++) {
cout << treasures[i] << " ";
}
cout << endl;
return 0;
}
文章来源:https://blog.csdn.net/weixin_74774974/article/details/135830356
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!