Implement a Binary Search Tree (BST) data structure in Rust that supports node insertion. Your implementation should maintain the BST property: for any given node, all nodes in the left subtree must have values less than the node's value, and all nodes in the right subtree must have values greater than the node's value.
- Create a BST structure that can store comparable values
- Implement the following operations:
- Create a new empty BST
- Insert a value into the BST while maintaining the BST property
- Include test cases demonstrating the correctness of your implementation
Your solution should support at least these operations:
// Create a new BST
let mut tree = BinarySearchTree::new();
// Insert values
tree.insert(value);
- The implementation must handle any type that can be ordered
- Duplicate values should be handled (you may choose to either ignore them or handle them in a specified way)
- You must use safe Rust (no unsafe blocks)
let mut tree = BinarySearchTree::new();
tree.insert(5);
tree.insert(3);
tree.insert(7);
Should create a tree structure like:
5
/ \
3 7
- Inserting into an empty tree
- Inserting values that go to the left child
- Inserting values that go to the right child
- Inserting multiple values to create a multi-level tree
- Handling duplicate values (document your approach)
- Implement a method to print the tree structure
- Add tree traversal methods (in-order, pre-order, or post-order)
- Implement a search operation
- Add deletion functionality
- Include performance analysis of your implementation