how to select the first x elements in a binary search tree?
-
18-10-2022 - |
Question
is there any existing algorithms for selecting the first x elements in a binary search tree? one way i could think of is to modify the tree traversal as follow:
int x = 0;
void inorder(tree* root, int *select_number, int *x){
if(root && select_number > x){
inorder(root->left, select_number,x);
//operations here
(*x)++;
inorder(root->right,select_number,x);
}
}
can this code work? is there a better way to do this? thank you so much!
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow