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

Function levelorder

publication/code/chapter08/bst.rs:352–376  ·  view source on GitHub ↗
(bst: Link<T,U>)

Source from the content-addressed store, hash-verified

350}
351
352fn levelorder<T, U>(bst: Link<T,U>)
353where T: Copy + Ord + Debug,
354 U: Copy + Debug
355{
356 if bst.is_none() { return; }
357
358 let size = bst.as_ref().unwrap().size();
359 let mut q = Queue::new(size);
360
361 let _r = q.enqueue(bst.as_ref().unwrap().clone());
362 while !q.is_empty() {
363 let front = q.dequeue().unwrap();
364 println!("key: {:?}, val: {:?}", front.key.unwrap(), front.val.unwrap());
365
366 match front.get_left() {
367 Some(left) => { let _r = q.enqueue(left); },
368 None => {},
369 }
370
371 match front.get_right() {
372 Some(right) => { let _r = q.enqueue(right); },
373 None => {},
374 }
375 }
376}
377
378fn main() {
379 basic();

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