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

Function levelorder

publication/code/chapter08/binary_tree.rs:314–335  ·  view source on GitHub ↗
(bt: Link<T>)

Source from the content-addressed store, hash-verified

312}
313
314fn levelorder<T: Clone + Ord + ToString + Debug>(bt: Link<T>) {
315 if bt.is_none() { return; }
316
317 let size = bt.as_ref().unwrap().size();
318 let mut q = Queue::new(size);
319
320 let _r = q.enqueue(bt.as_ref().unwrap().clone());
321 while !q.is_empty() {
322 let front = q.dequeue().unwrap();
323 println!("key: {:?}", front.get_key());
324
325 match front.get_left() {
326 Some(left) => { let _r = q.enqueue(left); },
327 None => {},
328 }
329
330 match front.get_right() {
331 Some(right) => { let _r = q.enqueue(right); },
332 None => {},
333 }
334 }
335}
336
337// 按照节点位置返回节点组成的字符串表达式: 外部实现
338fn oexp<T: Clone + Ord + ToString + Debug + Display>(bt: Link<T>) -> String {

Callers 1

orderFunction · 0.70

Calls 6

sizeMethod · 0.45
enqueueMethod · 0.45
is_emptyMethod · 0.45
dequeueMethod · 0.45
get_leftMethod · 0.45
get_rightMethod · 0.45

Tested by

no test coverage detected