The purpose of this library is to provide APIs that allows users to create memory efficient binary search tree, red-black tree and AVL tree. Besides, by using this library, users can investigate the performance difference between red-black tree and avl tree, which helps them deeply understand the algorithms.
```rust use tree_collections::prelude::*;
fn main() { let mut rbtree = RBTree::new(); rbtree.insert(1); rbtree.insert(2); rbtree.insert(3); rbtree.insert(4); rbtree.insert(5); rbtree.delete(3); println!("Red-Black Tree:"); rbtree.print(); println!("Number of leaves: {:?}", rbtree.countleaves()); println!("Height of tree: {:?}", rb_tree.height());
let mut avl_tree = AVLTree::new();
avl_tree.insert(1);
avl_tree.insert(2);
avl_tree.insert(3);
avl_tree.insert(4);
avl_tree.insert(5);
avl_tree.delete(3);
println!("AVL Tree:");
avl_tree.print();
println!("Number of leaves: {:?}", avl_tree.count_leaves());
println!("Height of tree: {:?}", avl_tree.height());
}
```
Building the documentation using
$ cargo doc
Find the API doc at
./target/doc/tree_collections/index.html
Run the user promote
$ cargo run
List of operations
$ insert
$ delete
$ count
$ height
$ inorder print
$ preorder print
$ empty
$ search
$ print tree
$ exit
Run the tests using
$ cargo test
Run the Benchmark using
$ cargo bench
Cargo version: 1.56^
Ref: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html