Add a public, owned BinaryTree<T> type backed by Box<Node<T>> with iterative pre-/in-/post-order and BFS level-order traversals. The repo currently has no first-class binary tree — Trie and SegmentTree use slabs/Vec-backed layouts; this module is the foundation for the rest of the v0.13.0 binary-tree issues.
API sketch
pub struct BinaryTree<T> { root: Option<Box<Node<T>>> }, Node { value: T, left, right }.
pub fn empty(), from_value(T), with_children(value, left, right), is_empty, height() -> usize, len() -> usize.
- Traversals returning
Vec<T> for T: Clone: preorder, inorder, postorder, level_order (BFS using VecDeque<&Node<T>>).
- Iterative implementations (avoid
unsafe; use explicit stacks).
Acceptance criteria
References
Mongan, Programming Interviews Exposed, Ch. 3 (Trees and Graphs).
Add a public, owned
BinaryTree<T>type backed byBox<Node<T>>with iterative pre-/in-/post-order and BFS level-order traversals. The repo currently has no first-class binary tree —TrieandSegmentTreeuse slabs/Vec-backed layouts; this module is the foundation for the rest of the v0.13.0 binary-tree issues.API sketch
pub struct BinaryTree<T> { root: Option<Box<Node<T>>> },Node { value: T, left, right }.pub fn empty(),from_value(T),with_children(value, left, right),is_empty,height() -> usize,len() -> usize.Vec<T>forT: Clone:preorder,inorder,postorder,level_order(BFS usingVecDeque<&Node<T>>).unsafe; use explicit stacks).Acceptance criteria
src/data_structures/binary_tree.rsand is declared insrc/data_structures/mod.rs.#[cfg(test)] mod testscovers empty, single node, left-only chain, right-only chain, perfect tree of height 3 (verifies all four traversal orders), and unbalanced tree.quickcheck) on randomly built trees:preorder.len() == inorder.len() == postorder.len() == level_order.len() == len().cargo fmt --check,cargo clippy --all-targets -- -D warnings, andcargo testall pass.References
Mongan, Programming Interviews Exposed, Ch. 3 (Trees and Graphs).