#include<iostream>
using namespace std;
typedef int ElemType;
typedef struct BTNode
{
ElemType data;
BTNode *pLchild;
BTNode *pRchild;
}BTNode, *BTree;
bool EQ(ElemType a, ElemType b)
{
if (a == b)
return true;
else
return false;
}
bool LT(ElemType a, ElemType b)
{
if (a < b)
return true;
else
return false;
}
bool RT(ElemType a, ElemType b)
{
if (a > b)
return true;
else
return false;
}
void Visit(ElemType a)
{
cout << a << " ";
}
void InitDTable(BTree &T)
{
T = NULL;
}
void DestroyDTable(BTree &T)
{
if (T)
{
if (T->pLchild)
DestroyDTable(T->pLchild);
if (T->pRchild)
DestroyDTable(T->pRchild);
delete T;
T = NULL;
}
}
BTree SearchBST__(BTree T, ElemType e)
{//查找成功返回指向该元素的值对应的结点的指针
//查找不成功返回NULL
if (!T || EQ(e, T->data))
return T;
else if (LT(e, T->data))
return SearchBST__(T->pLchild, e);
else
return SearchBST__(T->pRchild, e);
}
BTre
数据结构之二叉排序树
最新推荐文章于 2021-06-15 17:51:40 发布
