From 45fcfeef4b3396f4516ac04d2ca5f0f5140302fe Mon Sep 17 00:00:00 2001 From: p3i4gu5vn <1796370411@qq.com> Date: Wed, 16 Feb 2022 20:08:52 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E9=80=89=E6=8B=A9=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 选择排序 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 选择排序 diff --git a/选择排序 b/选择排序 new file mode 100644 index 0000000..72aaa3a --- /dev/null +++ b/选择排序 @@ -0,0 +1,20 @@ +void SelectionSort(int arr[], int length) +{ + int index, temp; + + for (int i = 0; i < length; i++) + { + index = i; + for (int j = i + 1; j < length; j++) + { + if (arr[j] < arr[index]) + index = j; + } + if (index != i) + { + temp = arr[i]; + arr[i] = arr[index]; + arr[index] = temp; + } + } +} \ No newline at end of file