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

Method preorder

code/chapter07/binary_tree.rs:67–72  ·  view source on GitHub ↗

前中后序遍历: 内部实现

(&self)

Source from the content-addressed store, hash-verified

65
66 // 前中后序遍历: 内部实现
67 fn preorder(&self) {
68 println!("kes is {:?}", &self.key);
69 if !self.left.is_none() { self.left.as_ref().unwrap().preorder(); }
70 if !self.right.is_none() { self.right.as_ref().unwrap().preorder(); }
71 // as_ref 获取节点引用,因为打印不能更改节点
72 }
73
74 fn inorder(&self) {
75 if !self.left.is_none() { self.left.as_ref().unwrap().inorder(); }

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected