Skip to content

Commit

Permalink
solve variant of search first greater value in bst 15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
quarzz committed May 13, 2023
1 parent 3356fd3 commit e79a38f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions epi_judge_cpp/search_first_greater_value_in_bst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ namespace {

return last_greater_node;
}

Node* variant(const unique_ptr<BstNode<int>>& tree, int val) {
auto cur = tree.get();
Node* last_equal = nullptr;

while (cur) {
if (cur->data == val)
last_equal = cur;

cur = cur->data < val ? cur->right.get() : cur->left.get();
}

return last_equal;
}
}

BstNode<int>* FindFirstGreaterThanK(
Expand Down

0 comments on commit e79a38f

Please sign in to comment.