mirror of
https://github.com/huihut/interview.git
synced 2025-12-18 21:14:38 +03:00
First Update
This commit is contained in:
14
Algorithm/BubbleSort.h
Normal file
14
Algorithm/BubbleSort.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// 冒泡排序
|
||||
|
||||
void BubbleSort(vector<int>& v) {
|
||||
int temp;
|
||||
for (int i = 0; i < v.size() - 1; ++i) {
|
||||
for (int j = 0; j < v.size() - 1 - i; ++j) {
|
||||
if (v[j] > v[j + 1]) { // 从小到大
|
||||
temp = v[j];
|
||||
v[j] = v[j + 1];
|
||||
v[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user