10 Star 56 Fork 24

编程语言算法集 / Rust

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hanoi.rs 594 Bytes
一键复制 编辑 原始数据 按行查看 历史
pub fn hanoi(n: i32, from: i32, to: i32, via: i32, moves: &mut Vec<(i32, i32)>) {
if n > 0 {
hanoi(n - 1, from, via, to, moves);
moves.push((from, to));
hanoi(n - 1, via, to, from, moves);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hanoi_simple() {
let correct_solution: Vec<(i32, i32)> =
vec![(1, 3), (1, 2), (3, 2), (1, 3), (2, 1), (2, 3), (1, 3)];
let mut our_solution: Vec<(i32, i32)> = Vec::new();
hanoi(3, 1, 3, 2, &mut our_solution);
assert_eq!(correct_solution, our_solution);
}
}
Rust
1
https://gitee.com/TheAlgorithms/Rust.git
git@gitee.com:TheAlgorithms/Rust.git
TheAlgorithms
Rust
Rust
master

搜索帮助