From 08cfb9458bf02d5efc53143e10bdcf991713acd8 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Thu, 24 Feb 2022 04:06:22 +0000 Subject: [PATCH] Update documentation --- src/lib.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5d801a1..6f636a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ //! //! That being said, there are some areas I would love to improve upon/include: //! - Write idiomatic code. +//! - Effectively use macros to reduce large portions of repetitive code. //! - Implement a **pretty_print()** function to display the binary search trees nicely. //! - Implement [Drop] trait for iterative node cleanup. //! - Pre-allocate space on the heap for nodes to reduce inefficiency of inserts. @@ -65,16 +66,18 @@ //! recursive_bst.remove(&50); // No change to tree as element does not exist //! assert_eq!(recursive_bst.size(), 4); //! -//! // View pre-order, in-order and post-order traversals +//! // View pre-order, in-order, post-order and level-order traversals //! assert_eq!(iterative_bst.pre_order_vec(), vec![&15, &5, &2, &25]); //! assert_eq!(iterative_bst.in_order_vec(), vec![&2, &5, &15, &25]); //! assert_eq!(iterative_bst.post_order_vec(), vec![&2, &5, &25, &15]); +//! assert_eq!(iterative_bst.level_order_vec(), vec![&15, &5, &25, &2]); //! //! assert_eq!(recursive_bst.pre_order_vec(), vec![&15, &5, &2, &25]); //! assert_eq!(recursive_bst.in_order_vec(), vec![&2, &5, &15, &25]); //! assert_eq!(recursive_bst.post_order_vec(), vec![&2, &5, &25, &15]); +//! assert_eq!(recursive_bst.level_order_vec(), vec![&15, &5, &25, &2]); //! -//! // Compare equality of trees +//! // Compare equality/in-equality of trees //! assert_eq!(iterative_bst.asc_order_vec(), recursive_bst.asc_order_vec()); //! assert_ne!(iterative_bst, IterativeBST::new()); //! assert_ne!(recursive_bst, RecursiveBST::new()); @@ -133,16 +136,36 @@ use std::vec::IntoIter; /// recursive_bst.remove(&50); // No change to tree as element does not exist /// assert_eq!(recursive_bst.size(), 4); /// -/// // View pre-order, in-order and post-order traversals +/// // Get height of tree +/// assert_eq!(iterative_bst.height(), Some(2)); +/// assert_eq!(recursive_bst.height(), Some(2)); +/// +/// // Get minimum element of tree +/// assert_eq!(iterative_bst.min(), Some(&2)); +/// assert_eq!(recursive_bst.min(), Some(&2)); +/// +/// // Get maximum element of tree +/// assert_eq!(iterative_bst.max(), Some(&25)); +/// assert_eq!(recursive_bst.max(), Some(&25)); +/// +/// // Retrieve reference to element in tree +/// assert_eq!(iterative_bst.retrieve(&5), Some(&5)); +/// assert_eq!(iterative_bst.retrieve(&100), None); // Element does not exist so None is returned +/// assert_eq!(recursive_bst.retrieve(&5), Some(&5)); +/// assert_eq!(recursive_bst.retrieve(&100), None); // Element does not exist so None is returned +/// +/// // View pre-order, in-order, post-order and level-order traversals /// assert_eq!(iterative_bst.pre_order_vec(), vec![&15, &5, &2, &25]); /// assert_eq!(iterative_bst.in_order_vec(), vec![&2, &5, &15, &25]); /// assert_eq!(iterative_bst.post_order_vec(), vec![&2, &5, &25, &15]); +/// assert_eq!(iterative_bst.level_order_vec(), vec![&15, &5, &25, &2]); /// /// assert_eq!(recursive_bst.pre_order_vec(), vec![&15, &5, &2, &25]); /// assert_eq!(recursive_bst.in_order_vec(), vec![&2, &5, &15, &25]); /// assert_eq!(recursive_bst.post_order_vec(), vec![&2, &5, &25, &15]); +/// assert_eq!(recursive_bst.level_order_vec(), vec![&15, &5, &25, &2]); /// -/// // Compare equality of trees +/// // Compare equality/in-equality of trees /// assert_eq!(iterative_bst.asc_order_vec(), recursive_bst.asc_order_vec()); /// assert_ne!(iterative_bst, IterativeBST::new()); /// assert_ne!(recursive_bst, RecursiveBST::new());