-->
当前位置:首页 > 题库 > 正文内容

函数题:Print the right subtree of X in BST

Luz3年前 (2022-01-18)题库1311
Given a binary search tree T, you are supposed to output all the elements in the right subtree of X, in *decreasing order*.

### Format of functions:
c
void print_right_subtree( Tree T, int X );

where Tree is defined as:
c
typedef struct TreeNode *Tree;
struct TreeNode {
int element;
Tree left;
Tree right;
};


### Sample program of judge:
c
#include <stdio.h>
#include <stdlib.h>

typedef struct TreeNode *Tree;
struct TreeNode {
int element;
Tree left;
Tree right;
};

Tree build_tree(); /* details omitted */

void print_right_subtree(Tree T, int X);

int main()
{
Tree T;
int X;

T = build_tree();
scanf("%d", &X);
print_right_subtree(T, X);

return 0;
}

/* Your function(s) will be put here */


### Sample Input
in
7
90 80 91 55 85 81 92
80



### Sample Output:

![sample.png](~/b1ad933c-4217-4290-b568-46c150d2b37e.png)
<br/><br/>

For the sample above, your program should output:
out
85 81 end



For an empy tree, simply output:

empty tree



In case X is not found in T, output:

x not found



where the letter "x" is NOT the value of X.





答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。