准备:
#include<iostream>
using namespace std;
typedef char ElemType;
#define END '#'
typedef struct BtNode
{
BtNode *leftchild;
BtNode *rightchild;
ElemType data;
}BtNode,*BinaryTree;
//购买结点
BtNode *Buynode()
{
BtNode *p=(BtNode *)malloc(sizeof(BtNode));
if(NULL==p) exit(1);
memset(p,0,sizeof(BtNode));
return p;
}
void *Freenode(BtNode *ptr)
{
free(ptr);
}
1.在二叉树中查找值X
//在二叉树中查找值x
BtNode * FindValue(BtNode *ptr,ElemType x)
{
ptr=root;
if(ptr==NULL ||ptr==x)
{
return ptr;
}
else
{
BtNode *p=FindValue(ptr->leftchild ,x);
if(p==NULL)
{
p=FindValue(ptr->rightchild ,x);
}
return p;
}
}
2.知道孩子结点,找到母亲结点
//知道孩子结点,找到母亲结点
BtNode * Parent(BtNode *ptr,BtNode *child)
{
if(ptr==NULLL