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

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

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

### Format of functions:
c
void print_left_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_left_subtree(Tree T, int X);

int main()
{
Tree T;
int X;

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

return 0;
}

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


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



### Sample Output:


![sample2.png](~/e5a2896d-f6bc-4427-a359-450d9e9b4377.png)

<br/><br/>

For the sample above, your program should output:
out
55 70 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.





答案:若无答案欢迎评论

发表评论

访客

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