Loading RustViz Engine...
Implement a pure functional BST enum: Empty or Node(Box<Self>, T, Box<Self>).
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub enum BST<T> {
Empty,
Node(Box<BST<T>>, T, Box<BST<T>>),
}
impl<T: Ord> BST<T> {
pub fn insert(&mut self, val: T) {
match self {
BST::Empty => *self = BST::Node(Box::new(BST::Empty), val, Box::new(BST::Empty)),
BST::Node(left, curr, right) => {
if val < *curr { left.insert(val); }
else if val > *curr { right.insert(val); }
}
}
}
}