diff --git a/.vscode/settings.json b/.vscode/settings.json index 1489981..e627288 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,7 @@ "streambuf": "cpp", "tuple": "cpp", "system_error": "cpp", - "xtr1common": "cpp" + "xtr1common": "cpp", + "limits": "cpp" } } \ No newline at end of file diff --git a/Algorithm/BubbleSort.h b/Algorithm/BubbleSort.h index c787fcb..3270519 100644 --- a/Algorithm/BubbleSort.h +++ b/Algorithm/BubbleSort.h @@ -1,5 +1,7 @@ // 冒泡排序 void BubbleSort(vector& 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) { diff --git a/Algorithm/BubbleSort_orderly.h b/Algorithm/BubbleSort_orderly.h index 5c39409..91ef293 100644 --- a/Algorithm/BubbleSort_orderly.h +++ b/Algorithm/BubbleSort_orderly.h @@ -1,5 +1,7 @@ // 冒泡排序(改进版) void BubbleSort_orderly(vector& v) { + if (v.size() <= 0) + return; int temp; bool orderly = false; for (int i = 0; i < v.size() - 1 && !orderly; ++i) { diff --git a/Algorithm/SelectionSort.h b/Algorithm/SelectionSort.h index d9c7b1e..3f3c70c 100644 --- a/Algorithm/SelectionSort.h +++ b/Algorithm/SelectionSort.h @@ -1,5 +1,7 @@ // 选择排序 void SelectionSort(vector& v) { + if (v.size() <= 0) + return; int min, temp; for (int i = 0; i < v.size() - 1; ++i) { min = i;