mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
feat: add rust docs (#815)
* feat: add rust docs * Import std types for built_in_hash doc
This commit is contained in:
@@ -532,7 +532,27 @@
|
||||
=== "Rust"
|
||||
|
||||
```rust title=""
|
||||
|
||||
/* 回溯算法框架 */
|
||||
fn backtrack(state: &mut State, choices: &Vec<Choice>, res: &mut Vec<State>) {
|
||||
// 判断是否为解
|
||||
if is_solution(state) {
|
||||
// 记录解
|
||||
record_solution(state, res);
|
||||
// 停止继续搜索
|
||||
return;
|
||||
}
|
||||
// 遍历所有选择
|
||||
for choice in choices {
|
||||
// 剪枝:判断选择是否合法
|
||||
if is_valid(state, choice) {
|
||||
// 尝试:做出选择,更新状态
|
||||
make_choice(state, choice);
|
||||
backtrack(state, choices, res);
|
||||
// 回退:撤销选择,恢复到之前的状态
|
||||
undo_choice(state, choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
Reference in New Issue
Block a user