【二叉树】查找二叉树
Description
题目描述
已知一棵二叉树,中序查找二叉树中值为x的结点,并指出是第几个结点。
例:如图二叉树的中序遍历序列为:29、12、8、15、23、5、10,中序查找15返回4,表示15在中序遍历序列的第四位。
Input
输入
第一行n为二叉树的结点个树,n<=100;第二行x表示要查找的结点的值;以下第一列数据是各结点的值(均不相等),第二列数据是左儿子结点编号,第三列数据是右儿子结点编号。
Output
输出
输出一个数即查找的结点编号。
Sample Input 1
7 15 5 2 3 12 4 5 10 0 0 29 0 0 15 6 7 8 0 0 23 0 0
Sample Output 1
4
#include<iostream>
using namespace std;
#define maxn 100;
typedef struct
{
int data;
int left,right;
}Tree;
Tree T[100];
int S[100];
int e=1;
void In(int n)
{
if(n==0)
return;
else
{
In(T[n].left);
//cout<<T[n].data;
S[e++]=T[n].data;