From 97e81f8620b865d142a27b806b8609bdc9b446e4 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sat, 19 Feb 2022 05:09:16 +0000 Subject: [PATCH] WIP Iterative implementation of BST --- src/lib.rs | 298 +++++++++++++++++++++ tests/iterative_bst.rs | 572 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 870 insertions(+) create mode 100644 tests/iterative_bst.rs diff --git a/src/lib.rs b/src/lib.rs index 87744b0..3ef853d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,6 +110,66 @@ impl Display for RecursiveBST { } } +impl PartialEq for IterativeBST { + fn eq(&self, other: &Self) -> bool { + self.sorted_vec() == other.sorted_vec() + } +} + +impl Extend for IterativeBST { + fn extend>(&mut self, iter: I) { + for value in iter.into_iter() { + self.insert(value) + } + } +} + +impl FromIterator for IterativeBST { + fn from_iter>(iter: I) -> Self { + let mut bst = IterativeBST::empty(); + bst.extend(iter); + bst + } +} + +impl From> for IterativeBST { + fn from(vec: Vec) -> Self { + let mut bst = IterativeBST::empty(); + for value in vec.into_iter() { + bst.insert(value); + } + bst + } +} + +impl From<&[T]> for IterativeBST { + fn from(slice: &[T]) -> Self { + let mut bst = IterativeBST::empty(); + for value in slice { + bst.insert((*value).clone()); + } + bst + } +} + +impl Clone for IterativeBST { + fn clone(&self) -> Self { + let mut bst = IterativeBST::empty(); + + for value in self.in_order_iter() { + bst.insert((*value).clone()); + } + + bst + } +} + +impl Display for IterativeBST { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.sorted_vec()) + } +} + impl Node { fn new(value: T) -> Node { Node { @@ -119,6 +179,21 @@ impl Node { } } + fn iterative_insert(root: &mut HeapNode, value: T) -> Result<(), ()> { + let mut current = root; + + while let Some(ref mut node) = current { + match value.cmp(&node.value) { + Ordering::Equal => return Err(()), + Ordering::Less => current = &mut node.left, + Ordering::Greater => current = &mut node.right, + } + } + *current = Some(Box::new(Node::new(value))); + + Ok(()) + } + fn recursive_insert(&mut self, value: T) -> Result<(), ()> { match value.cmp(&self.value) { Ordering::Equal => Err(()), @@ -238,6 +313,23 @@ impl Node { } } + fn iterative_pre_order_vec(node: &HeapNode) -> Vec<&T> { + let mut elements = Vec::new(); + let mut stack = vec![node.as_ref()]; + + while let Some(current) = stack.pop().unwrap_or(None) { + elements.push(¤t.value); + if current.right.is_some() { + stack.push(current.right.as_ref()); + } + if current.left.is_some() { + stack.push(current.left.as_ref()); + } + } + + elements + } + fn recursive_pre_order_vec<'a>(node: &'a HeapNode, elements: &mut Vec<&'a T>) { if let Some(ref node) = node { elements.push(&node.value); @@ -246,6 +338,25 @@ impl Node { } } + fn iterative_in_order_vec(node: &HeapNode) -> Vec<&T> { + let mut root = node; + let mut elements = Vec::new(); + let mut stack = Vec::new(); + + while !stack.is_empty() || root.is_some() { + if root.is_some() { + stack.push(root); + root = &root.as_ref().unwrap().left; + } else { + let node = stack.pop().unwrap(); + elements.push(&node.as_ref().unwrap().value); + root = &node.as_ref().unwrap().right; + } + } + + elements + } + fn recursive_in_order_vec<'a>(node: &'a HeapNode, elements: &mut Vec<&'a T>) { if let Some(ref node) = node { Node::recursive_in_order_vec(&node.left, elements); @@ -254,6 +365,44 @@ impl Node { } } + fn iterative_post_order_vec(node: &HeapNode) -> Vec<&T> { + let mut root = node; + let mut elements = Vec::new(); + let mut stack = Vec::new(); + + loop { + while let Some(current) = root { + if current.right.is_some() { + stack.push(current.right.as_ref().unwrap()); + } + stack.push(root.as_ref().unwrap()); + root = ¤t.left; + } + + if stack.is_empty() { + break; + } + + if let Some(current) = stack.pop() { + if !stack.is_empty() + && current.right.is_some() + && stack.last().unwrap().value == current.right.as_ref().unwrap().value + { + stack.pop(); + stack.push(current); + root = ¤t.right; + } else { + elements.push(¤t.value); + root = &None; + } + } else { + break; + } + } + + elements + } + fn recursive_post_order_vec<'a>(node: &'a HeapNode, elements: &mut Vec<&'a T>) { if let Some(ref node) = node { Node::recursive_post_order_vec(&node.left, elements); @@ -287,6 +436,155 @@ impl Node { } } +impl BinarySearchTree for IterativeBST { + fn empty() -> IterativeBST { + IterativeBST { + root: None, + size: 0, + } + } + + fn new(value: T) -> IterativeBST { + IterativeBST { + root: Some(Box::from(Node::new(value))), + size: 1, + } + } + + fn size(&self) -> usize { + self.size + } + + fn is_empty(&self) -> bool { + self.size == 0 + } + + fn insert(&mut self, value: T) { + if Node::iterative_insert(&mut self.root, value).is_ok() { + self.size += 1; + } + } + + fn contains(&self, value: &T) -> bool { + match self.root { + None => false, + Some(ref node) => node.recursive_contains(value), + } + } + + fn remove(&mut self, value: &T) { + if Node::recursive_remove(&mut self.root, value).is_ok() { + self.size -= 1; + } + } + + fn retrieve(&self, value: T) -> Option<&T> { + match self.root { + None => None, + Some(ref node) => node.recursive_retrieve(value), + } + } + + fn retrieve_as_mut(&mut self, value: T) -> Option<&mut T> { + match self.root { + None => None, + Some(ref mut node) => node.recursive_retrieve_as_mut(value), + } + } + + fn min(&self) -> Option<&T> { + match self.root { + None => None, + Some(ref node) => node.recursive_min(), + } + } + + fn max(&self) -> Option<&T> { + match self.root { + None => None, + Some(ref node) => node.recursive_max(), + } + } + + fn remove_min(&mut self) -> Option { + let removed_min = match self.root { + None => None, + Some(_) => Node::recursive_remove_min(&mut self.root), + }; + + if removed_min.is_some() { + self.size -= 1; + } + + removed_min + } + + fn remove_max(&mut self) -> Option { + let removed_max = match self.root { + None => None, + Some(_) => Node::recursive_remove_max(&mut self.root), + }; + + if removed_max.is_some() { + self.size -= 1; + } + + removed_max + } + + fn sorted_vec(&self) -> Vec<&T> { + Node::iterative_in_order_vec(&self.root) + } + + fn into_sorted_vec(self) -> Vec { + let mut elements = Vec::new(); + Node::recursive_consume_in_order_vec(self.root, &mut elements); + elements + } + + fn pre_order_vec(&self) -> Vec<&T> { + Node::iterative_pre_order_vec(&self.root) + } + + fn in_order_vec(&self) -> Vec<&T> { + Node::iterative_in_order_vec(&self.root) + } + + fn post_order_vec(&self) -> Vec<&T> { + Node::iterative_post_order_vec(&self.root) + } + + fn pre_order_iter(&self) -> IntoIter<&T> { + Node::iterative_pre_order_vec(&self.root).into_iter() + } + + fn in_order_iter(&self) -> IntoIter<&T> { + Node::iterative_in_order_vec(&self.root).into_iter() + } + + fn post_order_iter(&self) -> IntoIter<&T> { + Node::iterative_post_order_vec(&self.root).into_iter() + } + + fn into_pre_order_iter(self) -> IntoIter { + let mut elements = Vec::new(); + Node::recursive_consume_pre_order_vec(self.root, &mut elements); + elements.into_iter() + } + + fn into_in_order_iter(self) -> IntoIter { + let mut elements = Vec::new(); + Node::recursive_consume_in_order_vec(self.root, &mut elements); + elements.into_iter() + } + + fn into_post_order_iter(self) -> IntoIter { + let mut elements = Vec::new(); + Node::recursive_consume_post_order_vec(self.root, &mut elements); + elements.into_iter() + } +} + impl BinarySearchTree for RecursiveBST { fn empty() -> RecursiveBST { RecursiveBST { diff --git a/tests/iterative_bst.rs b/tests/iterative_bst.rs new file mode 100644 index 0000000..7059280 --- /dev/null +++ b/tests/iterative_bst.rs @@ -0,0 +1,572 @@ +use bst_rs::{BinarySearchTree, IterativeBST}; + +#[test] +fn can_insert_element() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(-1); + expected_bst.insert(0); + expected_bst.insert(1); + expected_bst.insert(2); + expected_bst.insert(-20); + + let mut actual_bst = IterativeBST::new(-1); + actual_bst.insert(0); + actual_bst.insert(1); + actual_bst.insert(1); + actual_bst.insert(2); + actual_bst.insert(-20); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn check_if_bst_is_empty() { + let mut bst = IterativeBST::empty(); + assert!(bst.is_empty()); + + bst.insert(1); + assert!(!bst.is_empty()); +} + +#[test] +fn check_element_exists() { + let mut bst = IterativeBST::empty(); + + bst.insert(1); + bst.insert(5); + + assert!(!bst.contains(&10)); + assert!(bst.contains(&1)); + assert!(bst.contains(&5)); +} + +#[test] +fn remove_root_element() { + let mut bst = IterativeBST::empty(); + bst.insert(0); + + assert!(!bst.is_empty()); + assert_eq!(bst.size(), 1); + + bst.remove(&0); + + assert!(bst.is_empty()); + assert_eq!(bst.size(), 0) +} + +#[test] +fn remove_leaf_node() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(5); + expected_bst.insert(4); + expected_bst.insert(6); + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(5); + actual_bst.insert(4); + actual_bst.insert(6); + actual_bst.insert(7); + + actual_bst.remove(&7); + + assert_eq!(actual_bst.size(), 3); + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn remove_single_right_node_with_children() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(5); + expected_bst.insert(4); + expected_bst.insert(7); + expected_bst.insert(8); + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(5); + actual_bst.insert(4); + actual_bst.insert(6); + actual_bst.insert(7); + actual_bst.insert(8); + + actual_bst.remove(&6); + + assert_eq!(actual_bst.size(), 4); + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn remove_single_left_node_with_children() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(5); + expected_bst.insert(3); + expected_bst.insert(2); + expected_bst.insert(6); + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(5); + actual_bst.insert(4); + actual_bst.insert(6); + actual_bst.insert(3); + actual_bst.insert(2); + + actual_bst.remove(&4); + + assert_eq!(actual_bst.size(), 4); + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn remove_node_with_two_children() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(3); + expected_bst.insert(8); + expected_bst.insert(15); + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(10); + actual_bst.insert(5); + actual_bst.insert(8); + actual_bst.insert(3); + actual_bst.insert(15); + + actual_bst.remove(&5); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn does_not_fail_when_removing_non_existing_element() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(5); + expected_bst.insert(8); + expected_bst.insert(3); + expected_bst.insert(15); + + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(10); + actual_bst.insert(5); + actual_bst.insert(8); + actual_bst.insert(3); + actual_bst.insert(15); + + actual_bst.remove(&20); + + assert_eq!(actual_bst.size(), 5); + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn retrieve_element() { + let mut bst = IterativeBST::empty(); + bst.insert(5); + bst.insert(10); + + let retrieved_value = bst.retrieve(5); + let invalid_value = bst.retrieve(15); + + assert_eq!(retrieved_value, Some(&5)); + assert_eq!(invalid_value, None); +} + +#[test] +fn retrieve_element_as_mut_and_modify_bst() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(2); + + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(10); + actual_bst.insert(5); + + let _retrieved_value_as_mut: &mut i32 = actual_bst.retrieve_as_mut(5).unwrap(); + *_retrieved_value_as_mut = 2; + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn get_min_from_bst() { + let mut bst = IterativeBST::empty(); + assert_eq!(bst.min(), None); + + bst.insert(5); + bst.insert(3); + bst.insert(1); + bst.insert(15); + + assert_eq!(bst.min(), Some(&1)); +} + +#[test] +fn get_max_from_bst() { + let mut bst = IterativeBST::empty(); + assert_eq!(bst.max(), None); + + bst.insert(5); + bst.insert(12); + bst.insert(1); + bst.insert(15); + + assert_eq!(bst.max(), Some(&15)); +} + +#[test] +fn remove_min_from_bst() { + let mut bst = IterativeBST::empty(); + assert_eq!(bst.remove_min(), None); + + bst.insert(5); + assert_eq!(bst.remove_min(), Some(5)); + assert_eq!(bst.size(), 0); + + bst.insert(3); + bst.insert(1); + bst.insert(2); + bst.insert(15); + + assert_eq!(bst.remove_min(), Some(1)); + assert!(bst.contains(&2)); + assert_eq!(bst.size(), 3); +} + +#[test] +fn remove_max_from_bst() { + let mut bst = IterativeBST::empty(); + assert_eq!(bst.remove_max(), None); + + bst.insert(5); + assert_eq!(bst.remove_max(), Some(5)); + assert_eq!(bst.size(), 0); + + bst.insert(3); + bst.insert(1); + bst.insert(15); + bst.insert(10); + + assert_eq!(bst.remove_max(), Some(15)); + assert!(bst.contains(&10)); + assert_eq!(bst.size(), 3); +} + +#[test] +fn pre_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut pre_order_iter = bst.pre_order_iter(); + + assert_eq!(pre_order_iter.next(), Some(&3)); + assert_eq!(pre_order_iter.next(), Some(&1)); + assert_eq!(pre_order_iter.next(), Some(&2)); + assert_eq!(pre_order_iter.next(), Some(&4)); + assert_eq!(pre_order_iter.next(), Some(&5)); + assert_eq!(pre_order_iter.next(), None); + + bst.insert(10); + + let mut another_pre_order_iter = bst.pre_order_iter(); + + assert_eq!(another_pre_order_iter.next(), Some(&3)); + assert_eq!(another_pre_order_iter.next(), Some(&1)); + assert_eq!(another_pre_order_iter.next(), Some(&2)); + assert_eq!(another_pre_order_iter.next(), Some(&4)); + assert_eq!(another_pre_order_iter.next(), Some(&5)); + assert_eq!(another_pre_order_iter.next(), Some(&10)); + assert_eq!(another_pre_order_iter.next(), None); +} + +#[test] +fn in_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut in_order_iter = bst.in_order_iter(); + + assert_eq!(in_order_iter.next(), Some(&1)); + assert_eq!(in_order_iter.next(), Some(&2)); + assert_eq!(in_order_iter.next(), Some(&3)); + assert_eq!(in_order_iter.next(), Some(&4)); + assert_eq!(in_order_iter.next(), Some(&5)); + assert_eq!(in_order_iter.next(), None); + + bst.insert(6); + + let mut another_in_order_iter = bst.in_order_iter(); + + assert_eq!(another_in_order_iter.next(), Some(&1)); + assert_eq!(another_in_order_iter.next(), Some(&2)); + assert_eq!(another_in_order_iter.next(), Some(&3)); + assert_eq!(another_in_order_iter.next(), Some(&4)); + assert_eq!(another_in_order_iter.next(), Some(&5)); + assert_eq!(another_in_order_iter.next(), Some(&6)); + assert_eq!(another_in_order_iter.next(), None); +} + +#[test] +fn post_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut post_order_iter = bst.post_order_iter(); + println!("{:?}", bst); + + assert_eq!(post_order_iter.next(), Some(&2)); + assert_eq!(post_order_iter.next(), Some(&1)); + assert_eq!(post_order_iter.next(), Some(&5)); + assert_eq!(post_order_iter.next(), Some(&4)); + assert_eq!(post_order_iter.next(), Some(&3)); + assert_eq!(post_order_iter.next(), None); + + bst.insert(10); + + let mut another_post_order_iter = bst.post_order_iter(); + + assert_eq!(another_post_order_iter.next(), Some(&2)); + assert_eq!(another_post_order_iter.next(), Some(&1)); + assert_eq!(another_post_order_iter.next(), Some(&10)); + assert_eq!(another_post_order_iter.next(), Some(&5)); + assert_eq!(another_post_order_iter.next(), Some(&4)); + assert_eq!(another_post_order_iter.next(), Some(&3)); + assert_eq!(another_post_order_iter.next(), None); +} + +#[test] +fn into_pre_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut pre_order_iter = bst.into_pre_order_iter(); + + assert_eq!(pre_order_iter.next(), Some(3)); + assert_eq!(pre_order_iter.next(), Some(1)); + assert_eq!(pre_order_iter.next(), Some(2)); + assert_eq!(pre_order_iter.next(), Some(4)); + assert_eq!(pre_order_iter.next(), Some(5)); + assert_eq!(pre_order_iter.next(), None); +} + +#[test] +fn into_in_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut in_order_iter = bst.into_in_order_iter(); + + assert_eq!(in_order_iter.next(), Some(1)); + assert_eq!(in_order_iter.next(), Some(2)); + assert_eq!(in_order_iter.next(), Some(3)); + assert_eq!(in_order_iter.next(), Some(4)); + assert_eq!(in_order_iter.next(), Some(5)); + assert_eq!(in_order_iter.next(), None); +} + +#[test] +fn into_post_order_iter() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + let mut post_order_traversal = bst.into_post_order_iter(); + + assert_eq!(post_order_traversal.next(), Some(2)); + assert_eq!(post_order_traversal.next(), Some(1)); + assert_eq!(post_order_traversal.next(), Some(5)); + assert_eq!(post_order_traversal.next(), Some(4)); + assert_eq!(post_order_traversal.next(), Some(3)); + assert_eq!(post_order_traversal.next(), None); +} + +#[test] +fn get_sorted_vec() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + assert_eq!(bst.sorted_vec(), vec![&1, &2, &3, &4, &5]); +} + +#[test] +fn bst_into_sorted_vec() { + let mut bst = IterativeBST::empty(); + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + assert_eq!(bst.into_sorted_vec(), vec![1, 2, 3, 4, 5]); +} + +#[test] +fn get_pre_order_vec() { + let mut bst = IterativeBST::empty(); + assert!(bst.pre_order_vec().is_empty()); + + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + assert_eq!(bst.pre_order_vec(), vec![&3, &1, &2, &4, &5]); +} + +#[test] +fn get_in_order_vec() { + let mut bst = IterativeBST::empty(); + assert!(bst.in_order_vec().is_empty()); + + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + + assert_eq!(bst.in_order_vec(), vec![&1, &2, &3, &4, &5]); +} + +#[test] +fn get_post_order_vec() { + let mut bst = IterativeBST::empty(); + assert!(bst.post_order_vec().is_empty()); + + bst.insert(3); + bst.insert(4); + bst.insert(5); + bst.insert(1); + bst.insert(2); + assert_eq!(bst.post_order_vec(), vec![&2, &1, &5, &4, &3]); +} + +#[test] +fn create_bst_from_vec() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(20); + expected_bst.insert(5); + expected_bst.insert(30); + + let actual_bst = IterativeBST::from(vec![10, 20, 5, 30]); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn create_bst_from_slice() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(20); + expected_bst.insert(5); + expected_bst.insert(30); + + let actual_bst = IterativeBST::from(vec![10, 20, 5, 30].as_slice()); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn create_bst_from_into_vec() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(10); + expected_bst.insert(20); + expected_bst.insert(5); + expected_bst.insert(30); + + let actual_bst: IterativeBST = vec![10, 20, 5, 30].into(); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn extend_bst_from_iter() { + let vec = vec![8, 1, 10]; + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(3); + expected_bst.insert(2); + expected_bst.insert(5); + expected_bst.insert(8); + expected_bst.insert(1); + expected_bst.insert(10); + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(3); + actual_bst.insert(2); + actual_bst.insert(5); + + actual_bst.extend(vec.into_iter()); + + assert_eq!(actual_bst.size(), 6); + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn create_bst_from_iter() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(3); + expected_bst.insert(2); + expected_bst.insert(5); + expected_bst.insert(8); + expected_bst.insert(1); + expected_bst.insert(10); + + let actual_bst = IterativeBST::from_iter(vec![3, 2, 5, 8, 1, 10].into_iter()); + + assert_eq!(actual_bst, expected_bst); +} + +#[test] +fn clone_bst() { + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(3); + expected_bst.insert(2); + expected_bst.insert(5); + expected_bst.insert(8); + expected_bst.insert(1); + expected_bst.insert(10); + + let cloned_bst = expected_bst.clone(); + + assert_eq!(cloned_bst, expected_bst); +} + +#[test] +fn clone_into_another_bst() { + let mut actual_bst = IterativeBST::empty(); + actual_bst.insert(3); + actual_bst.insert(2); + let mut expected_bst = IterativeBST::empty(); + expected_bst.insert(3); + expected_bst.insert(2); + expected_bst.insert(5); + expected_bst.insert(8); + expected_bst.insert(1); + expected_bst.insert(10); + assert_ne!(actual_bst, expected_bst); + + actual_bst.clone_from(&expected_bst); + + assert_eq!(actual_bst, expected_bst); +} \ No newline at end of file