Skip to content

Commit

Permalink
feat(extending): simplify conditional checks in BinaryTreeNode methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze7111 committed Dec 13, 2024
1 parent 189125a commit 8d064ec
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions assets/code/language/extending.hlx
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,27 @@ extend BinaryTreeNode::<i32> {
self.left = null;
self.right = null;
}

fn insert(self, value: i32) {
if value < self.value {
if self.left? {
if self.left?:
self.left.insert(value);
} else {
else:
self.left = BinaryTreeNode(value);
}
} else {
if self.right? {
if self.right?:
self.right.insert(value);
} else {
else:
self.right = BinaryTreeNode(value);
}
}
}

fn find(self, value: i32) -> bool {
if value == self.value {
if value == self.value:
return true;
} else if value < self.value {
else if value < self.value:
return self.left? && self.left.find(value);
} else {
else:
return self.right? && self.right.find(value);
}
}
}

0 comments on commit 8d064ec

Please sign in to comment.