fix several bugs

This commit is contained in:
krahets 2023-10-17 23:45:31 +08:00
parent 51405c0669
commit 5392afd44b
14 changed files with 15 additions and 15 deletions

View file

@ -15,7 +15,7 @@ void printFunc(vector *v, void *p) {
} }
/* 前序遍历:例题一 */ /* 前序遍历:例题一 */
static void preOrder(TreeNode *root) { void preOrder(TreeNode *root) {
if (root == NULL) { if (root == NULL) {
return; return;
} }

View file

@ -1,3 +1,3 @@
add_executable(binary_search_recur binary_search_recur.c) add_executable(binary_search_recur binary_search_recur.c)
add_executable(hanota hanota.c)
add_executable(build_tree build_tree.c) add_executable(build_tree build_tree.c)
add_executable(hanota hanota.c)

View file

@ -19,7 +19,7 @@ typedef struct pair Pair;
/* 链表节点 */ /* 链表节点 */
struct node { struct node {
Pair *pair; Pair *pair;
struct Node *next; struct node *next;
}; };
typedef struct node Node; typedef struct node Node;

View file

@ -16,7 +16,7 @@ void backtrack(vector<int> &state, const vector<int> &choices, vector<bool> &sel
// 遍历所有选择 // 遍历所有选择
for (int i = 0; i < choices.size(); i++) { for (int i = 0; i < choices.size(); i++) {
int choice = choices[i]; int choice = choices[i];
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if (!selected[i]) { if (!selected[i]) {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
selected[i] = true; selected[i] = true;

View file

@ -17,7 +17,7 @@ public class permutations_i {
// 遍历所有选择 // 遍历所有选择
for (int i = 0; i < choices.Length; i++) { for (int i = 0; i < choices.Length; i++) {
int choice = choices[i]; int choice = choices[i];
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if (!selected[i]) { if (!selected[i]) {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
selected[i] = true; selected[i] = true;

View file

@ -19,7 +19,7 @@ void backtrack(
// //
for (int i = 0; i < choices.length; i++) { for (int i = 0; i < choices.length; i++) {
int choice = choices[i]; int choice = choices[i];
// //
if (!selected[i]) { if (!selected[i]) {
// //
selected[i] = true; selected[i] = true;

View file

@ -14,7 +14,7 @@ func backtrackI(state *[]int, choices *[]int, selected *[]bool, res *[][]int) {
// 遍历所有选择 // 遍历所有选择
for i := 0; i < len(*choices); i++ { for i := 0; i < len(*choices); i++ {
choice := (*choices)[i] choice := (*choices)[i]
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if !(*selected)[i] { if !(*selected)[i] {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
(*selected)[i] = true (*selected)[i] = true

View file

@ -19,7 +19,7 @@ public class permutations_i {
// 遍历所有选择 // 遍历所有选择
for (int i = 0; i < choices.length; i++) { for (int i = 0; i < choices.length; i++) {
int choice = choices[i]; int choice = choices[i];
// 剪枝不允许重复选择元素 不允许重复选择相等元素 // 剪枝不允许重复选择元素
if (!selected[i]) { if (!selected[i]) {
// 尝试做出选择更新状态 // 尝试做出选择更新状态
selected[i] = true; selected[i] = true;

View file

@ -13,7 +13,7 @@ function backtrack(state, choices, selected, res) {
} }
// 遍历所有选择 // 遍历所有选择
choices.forEach((choice, i) => { choices.forEach((choice, i) => {
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if (!selected[i]) { if (!selected[i]) {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
selected[i] = true; selected[i] = true;

View file

@ -14,7 +14,7 @@ fn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: &
// 遍历所有选择 // 遍历所有选择
for i in 0..choices.len() { for i in 0..choices.len() {
let choice = choices[i]; let choice = choices[i];
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if !selected[i] { if !selected[i] {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
selected[i] = true; selected[i] = true;

View file

@ -13,7 +13,7 @@ func backtrack(state: inout [Int], choices: [Int], selected: inout [Bool], res:
} }
// //
for (i, choice) in choices.enumerated() { for (i, choice) in choices.enumerated() {
// //
if !selected[i] { if !selected[i] {
// //
selected[i] = true selected[i] = true

View file

@ -18,7 +18,7 @@ function backtrack(
} }
// 遍历所有选择 // 遍历所有选择
choices.forEach((choice, i) => { choices.forEach((choice, i) => {
// 剪枝:不允许重复选择元素 且 不允许重复选择相等元素 // 剪枝:不允许重复选择元素
if (!selected[i]) { if (!selected[i]) {
// 尝试:做出选择,更新状态 // 尝试:做出选择,更新状态
selected[i] = true; selected[i] = true;

View file

@ -233,9 +233,9 @@
```rust title="list.rs" ```rust title="list.rs"
/* 访问元素 */ /* 访问元素 */
let num: i32 = nums[1]; // 访问索引 1 处的元素 let num: i32 = nums[1]; // 访问索引 1 处的元素
/* 更新元素 */ /* 更新元素 */
nums[1] = 0; // 将索引 1 处的元素更新为 0 nums[1] = 0; // 将索引 1 处的元素更新为 0
``` ```
=== "C" === "C"

View file

@ -223,7 +223,7 @@ $$
=== "Go" === "Go"
```go title="built_in_hash.go" ```go title="built_in_hash.go"
// Go 未提供内置 hash code 函数
``` ```
=== "Swift" === "Swift"