문제

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