Expand description
Building a binary tree from an iterator.
Examples
use bin_tree::{IteratorEx, Node};
#[derive(Clone, Default, PartialEq, Eq, Debug)]
struct NodeStr(String);
impl Node for NodeStr {
fn new_parent(self, right: Self) -> Self {
Self("[".to_owned() + &self.0 + ", " + &right.0 + "]")
}
fn new_parent_from_single(self) -> Self {
self
}
}
let x = (0..10).map(|v| NodeStr(v.to_string())).build_tree();
assert_eq!(x, Some(NodeStr("[[[[0, 1], [2, 3]], [[4, 5], [6, 7]]], [8, 9]]".to_string())));
Traits
- The trait extends the functionality of the standard
Iterator
trait by adding thebuild_tree
method. - A trait representing a node in a binary tree.