summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRaito Bezarius2024-04-16 17:46:09 +0200
committerRaito Bezarius2024-04-16 17:46:09 +0200
commit117cd1c0afbc50ffc5a90473cb4c01185188711e (patch)
treef027cdb20d2ef64cc0870be15101666f0ec903ed /src
parent550bb293463989a431c8de8c6df392f5746ecb00 (diff)
feat: add `find` function
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/main.rs13
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 = &current_node.right,
+ Ordering::Equal => return true,
+ Ordering::Greater => current_tree = &current_node.left,
+ }
+ }
+
+ false
+ }
pub fn insert(&mut self, value: T) -> bool {
let mut current_tree = &mut self.root;