From 51e52121dce697c1a9a883e63590472354d1c4c5 Mon Sep 17 00:00:00 2001 From: mellowrsa <87369532+mellowrsa@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:05:52 +0800 Subject: [PATCH 1/2] Update time_complexity.md --- .../time_complexity.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/chapter_computational_complexity/time_complexity.md b/docs/chapter_computational_complexity/time_complexity.md index 09aee7b79..ea523b46d 100644 --- a/docs/chapter_computational_complexity/time_complexity.md +++ b/docs/chapter_computational_complexity/time_complexity.md @@ -1434,11 +1434,14 @@ $$ for (int i = n - 1; i > 0; i--) { // 内循环:冒泡操作 for (int j = 0; j < i; j++) { - // 交换 nums[j] 与 nums[j + 1] - int tmp = nums[j]; - nums[j] = nums[j + 1]; - nums[j + 1] = tmp; - count += 3; // 元素交换包含 3 个单元操作 + if (nums[j] > nums [j+1]) + { + // 交换 nums[j] 与 nums[j + 1] + int tmp = nums[j]; + nums[j] = nums[j + 1]; + nums[j + 1] = tmp; + count += 3; // 元素交换包含 3 个单元操作 + } } } From 483925686f7ac8103e88ec02c2f841d82e0b5153 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Wed, 11 Jan 2023 02:45:28 +0800 Subject: [PATCH 2/2] Update time_complexity.md --- docs/chapter_computational_complexity/time_complexity.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/chapter_computational_complexity/time_complexity.md b/docs/chapter_computational_complexity/time_complexity.md index ea523b46d..def052c92 100644 --- a/docs/chapter_computational_complexity/time_complexity.md +++ b/docs/chapter_computational_complexity/time_complexity.md @@ -1434,7 +1434,7 @@ $$ for (int i = n - 1; i > 0; i--) { // 内循环:冒泡操作 for (int j = 0; j < i; j++) { - if (nums[j] > nums [j+1]) + if (nums[j] > nums [j + 1]) { // 交换 nums[j] 与 nums[j + 1] int tmp = nums[j];