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!

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top