Skip to content

feat(data-structures): add owned binary tree with iterative traversals#530

Merged
0xDevNinja merged 1 commit into
mainfrom
feat/data-structures/binary-tree
May 7, 2026
Merged

feat(data-structures): add owned binary tree with iterative traversals#530
0xDevNinja merged 1 commit into
mainfrom
feat/data-structures/binary-tree

Conversation

@0xDevNinja
Copy link
Copy Markdown
Owner

Summary

  • New src/data_structures/binary_tree.rs providing BinaryTree<T> and Node<T> with Box-owned children and an Option<Box<Node<T>>> root.
  • Builders new, leaf, node; iterative inorder / preorder / postorder (explicit Vec stack), level_order (VecDeque), plus height and size (counting nodes), all returning Vec<&T> where applicable and avoiding recursion to stay safe on deep trees.
  • Module-level docs cover semantics and complexity (O(n) time, O(h) / O(w) aux space); inline #[cfg(test)] mod tests covers the empty tree, single node, the classic 7-node tree (root 1, children 2/3, grandchildren 4/5/6/7) for every traversal/height/size, plus a left-skewed tree and Default.

Test plan

  • cargo fmt
  • cargo build
  • cargo clippy --all-targets -- -D warnings
  • cargo test binary_tree --lib

Closes #324

@0xDevNinja 0xDevNinja force-pushed the feat/data-structures/binary-tree branch from ac2e396 to 56646a5 Compare May 7, 2026 09:17
@0xDevNinja 0xDevNinja merged commit 182a4df into main May 7, 2026
@0xDevNinja 0xDevNinja deleted the feat/data-structures/binary-tree branch May 7, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add binary tree (owned, recursive) with traversals

1 participant