diff options
author | Raito Bezarius | 2024-04-16 17:46:09 +0200 |
---|---|---|
committer | Raito Bezarius | 2024-04-16 17:46:09 +0200 |
commit | 117cd1c0afbc50ffc5a90473cb4c01185188711e (patch) | |
tree | f027cdb20d2ef64cc0870be15101666f0ec903ed /src/main.rs | |
parent | 550bb293463989a431c8de8c6df392f5746ecb00 (diff) |
feat: add `find` function
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 9cf9492..59642d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,19 @@ impl<T: Ord> AVLTreeSet<T> { Self { root: None } } + pub fn find(self, value: T) -> bool { + let mut current_tree = &self.root; + + while let Some(current_node) = current_tree { + match current_node.value.cmp(&value) { + Ordering::Less => current_tree = ¤t_node.right, + Ordering::Equal => return true, + Ordering::Greater => current_tree = ¤t_node.left, + } + } + + false + } pub fn insert(&mut self, value: T) -> bool { let mut current_tree = &mut self.root; |