From 7645bf97df4448feb1efabf5bcec23718f0c7d60 Mon Sep 17 00:00:00 2001 From: krahets Date: Wed, 3 May 2023 18:29:57 +0800 Subject: [PATCH] build --- chapter_backtracking/backtracking_algorithm.md | 7 +++++-- chapter_backtracking/permutations_problem.md | 8 ++++++++ chapter_sorting/quick_sort.md | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/chapter_backtracking/backtracking_algorithm.md b/chapter_backtracking/backtracking_algorithm.md index b40bdad2b..ae24f0870 100644 --- a/chapter_backtracking/backtracking_algorithm.md +++ b/chapter_backtracking/backtracking_algorithm.md @@ -502,6 +502,7 @@ def backtrack(state, choices, res): if (isValid(state, choice)) { // 尝试:做出选择,更新状态 makeChoice(state, choice); + // 进行下一轮选择 backtrack(state, Arrays.asList(choice.left, choice.right), res); // 回退:撤销选择,恢复到之前的状态 undoChoice(state, choice); @@ -552,6 +553,7 @@ def backtrack(state, choices, res): if (isValid(state, choice)) { // 尝试:做出选择,更新状态 makeChoice(state, choice); + // 进行下一轮选择 vector nextChoices{choice->left, choice->right}; backtrack(state, nextChoices, res); // 回退:撤销选择,恢复到之前的状态 @@ -597,6 +599,7 @@ def backtrack(state, choices, res): if is_valid(state, choice): # 尝试:做出选择,更新状态 make_choice(state, choice) + # 进行下一轮选择 backtrack(state, [choice.left, choice.right], res) # 回退:撤销选择,恢复到之前的状态 undo_choice(state, choice) @@ -708,8 +711,8 @@ def backtrack(state, choices, res): if (isValid(state, choice)) { // 尝试:做出选择,更新状态 makeChoice(state, choice); - List nextChoices = new List() { choice.left, choice.right }; - backtrack(state, nextChoices, res); + // 进行下一轮选择 + backtrack(state, new List { choice.left, choice.right }, res); // 回退:撤销选择,恢复到之前的状态 undoChoice(state, choice); } diff --git a/chapter_backtracking/permutations_problem.md b/chapter_backtracking/permutations_problem.md index 6b5f85644..ffd677f92 100644 --- a/chapter_backtracking/permutations_problem.md +++ b/chapter_backtracking/permutations_problem.md @@ -52,6 +52,7 @@ comments: true // 尝试:做出选择,更新状态 selected[i] = true; state.add(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; @@ -86,6 +87,7 @@ comments: true // 尝试:做出选择,更新状态 selected[i] = true; state.push_back(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; @@ -122,6 +124,7 @@ comments: true # 尝试:做出选择,更新状态 selected[i] = True state.append(choice) + # 进行下一轮选择 backtrack(state, choices, selected, res) # 回退:撤销选择,恢复到之前的状态 selected[i] = False @@ -184,6 +187,7 @@ comments: true // 尝试:做出选择,更新状态 selected[i] = true; state.Add(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; @@ -264,6 +268,7 @@ comments: true duplicated.add(choice); // 记录选择过的元素值 selected[i] = true; state.add(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; @@ -300,6 +305,7 @@ comments: true duplicated.emplace(choice); // 记录选择过的元素值 selected[i] = true; state.push_back(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; @@ -338,6 +344,7 @@ comments: true duplicated.add(choice) # 记录选择过的元素值 selected[i] = True state.append(choice) + # 进行下一轮选择 backtrack(state, choices, selected, res) # 回退:撤销选择,恢复到之前的状态 selected[i] = False @@ -402,6 +409,7 @@ comments: true duplicated.Add(choice); // 记录选择过的元素值 selected[i] = true; state.Add(choice); + // 进行下一轮选择 backtrack(state, choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; diff --git a/chapter_sorting/quick_sort.md b/chapter_sorting/quick_sort.md index ee8930640..d23fbf6b1 100755 --- a/chapter_sorting/quick_sort.md +++ b/chapter_sorting/quick_sort.md @@ -202,6 +202,13 @@ comments: true === "C" ```c title="quick_sort.c" + /* 元素交换 */ + void swap(int nums[], int i, int j) { + int tmp = nums[i]; + nums[i] = nums[j]; + nums[j] = tmp; + } + /* 快速排序类 */ // 快速排序类-哨兵划分 int partition(int nums[], int left, int right) {