mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-28 19:43:31 +08:00
c++
This commit is contained in:
parent
b384243156
commit
f7b6ec625d
@ -17,4 +17,47 @@ This article offers a sample of basic Markdown.
|
|||||||
|
|
||||||
# 正文开始
|
# 正文开始
|
||||||
|
|
||||||
https://www.nowcoder.com/login?callBack=%2Fprofile%2F319706329%2FcodeBookDetail%3FsubmissionId%3D416948138
|
https://www.nowcoder.com/login?callBack=%2Fprofile%2F319706329%2FcodeBookDetail%3FsubmissionId%3D416948138
|
||||||
|
|
||||||
|
## 冒泡排序(从小到大)
|
||||||
|
```cpp
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
//冒泡排序
|
||||||
|
vector<int> MySort(vector<int>& arr) {
|
||||||
|
int n = arr.size();
|
||||||
|
for(int i = 0; i< n-1;i++)
|
||||||
|
{
|
||||||
|
for(int j = 0 ; j <n -i-1 ;j++)
|
||||||
|
{
|
||||||
|
if(arr[j] <= arr[j+1])continue;
|
||||||
|
int t = arr[j];
|
||||||
|
arr[j] = arr[j+1];
|
||||||
|
arr[j+1] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
vector<int> arr{5,2,3,1,4};
|
||||||
|
for(auto it : arr)
|
||||||
|
{
|
||||||
|
cout<<it<<" ";
|
||||||
|
}
|
||||||
|
cout<<" "<<endl;
|
||||||
|
MySort(arr);
|
||||||
|
for(auto it : arr)
|
||||||
|
{
|
||||||
|
cout<<it<<" ";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|

|
Binary file not shown.
After Width: | Height: | Size: 265 KiB |
Loading…
Reference in New Issue
Block a user