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

Function get_exp

code/chapter07/binary_tree.rs:113–122  ·  view source on GitHub ↗

按照节点位置返回节点组成的字符串

(bt: Link<T>)

Source from the content-addressed store, hash-verified

111
112// 按照节点位置返回节点组成的字符串
113fn get_exp<T: Clone + Debug + Display>(bt: Link<T>) -> String {
114 let mut exp = "".to_string();
115 if !bt.is_none() {
116 exp = "(".to_string() + &get_exp(bt.as_ref().unwrap().get_left());
117 exp += &bt.as_ref().unwrap().get_key().to_string();
118 exp += &(get_exp(bt.as_ref().unwrap().get_right()) + ")");
119 }
120
121 exp
122}
123
124fn main() {
125 let mut bt = BinaryTree::new('a');

Callers 1

mainFunction · 0.85

Calls 4

to_stringMethod · 0.45
get_leftMethod · 0.45
get_keyMethod · 0.45
get_rightMethod · 0.45

Tested by

no test coverage detected