mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
修改冒泡选择排序的边界值检测
This commit is contained in:
parent
bcc6a28cd1
commit
97d065894c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -11,6 +11,7 @@
|
|||
"streambuf": "cpp",
|
||||
"tuple": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xtr1common": "cpp"
|
||||
"xtr1common": "cpp",
|
||||
"limits": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
// 冒泡排序
|
||||
void BubbleSort(vector<int>& v) {
|
||||
if (v.size() <= 0)
|
||||
return;
|
||||
int temp;
|
||||
for (int i = 0; i < v.size() - 1; ++i) {
|
||||
for (int j = 0; j < v.size() - 1 - i; ++j) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// 冒泡排序(改进版)
|
||||
void BubbleSort_orderly(vector<int>& v) {
|
||||
if (v.size() <= 0)
|
||||
return;
|
||||
int temp;
|
||||
bool orderly = false;
|
||||
for (int i = 0; i < v.size() - 1 && !orderly; ++i) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// 选择排序
|
||||
void SelectionSort(vector<int>& v) {
|
||||
if (v.size() <= 0)
|
||||
return;
|
||||
int min, temp;
|
||||
for (int i = 0; i < v.size() - 1; ++i) {
|
||||
min = i;
|
||||
|
|
Loading…
Reference in New Issue
Block a user