//二叉排序树输出所有值大于k的
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define Max 10
typedef struct treenode {
char data;
struct treenode* lchild, * rchild;
}treenode, * tree;
void creatTree(tree& t) {
char ch;
ch = getchar();
if (ch == '#') t = NULL;
else {
t = (treenode*)malloc(sizeof(treenode));
t->data = ch;
t->lchild = NULL;
t->rchild = NULL;
creatTree(t->lchild);
creatTree(t->rchild);
}
}
char output(tree t, char A) {
if (t == NULL)
return 'no';
if(t->rchild!=NULL)//递归输出右子树结点
output(t->rchild, A);
if (t->data > A) //只输出大于A的
printf("%c", t->data);
if (t->rchild != NULL)//递归输出左子树结点
output(t->lchild, A);
}
int main() {
tree t;
creatTree(t);
output(t, 'B');
return 0;
}
二叉排序树输出所有值大于k的
于 2022-10-30 22:44:45 首次发布