MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / hanoi

Function hanoi

publication/code/chapter05/hanoi.rs:4–10  ·  view source on GitHub ↗

p : pole 杆

(height: u32, src_p: &str, des_p: &str, mid_p: &str)

Source from the content-addressed store, hash-verified

2
3// p : pole 杆
4fn hanoi(height: u32, src_p: &str, des_p: &str, mid_p: &str) {
5 if height >= 1 {
6 hanoi(height - 1, src_p, mid_p, des_p);
7 println!("move disk[{height}] from {src_p} to {des_p}");
8 hanoi(height - 1, mid_p, des_p, src_p);
9 }
10}
11
12fn main() {
13 hanoi(1, "A", "B", "C");

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected