数据结构-中序遍历线索二叉树,堆排序
线索化二叉树的定义
typedef char ElemType;
typedef enum{LINK = 0,THREAD = 1}PointTag;
typedef struct BiThrNode
{
BiThrNode *leftchild;
BiThrNode *rightchild;
PointTag Ltag,Rtag; //枚举
ElemType data;
}BiThrNode * , ThreadBinaryTree;
中序遍历线索二叉树
BiThrNode *frist(BiThrNode *str) //前驱
{
while (str != NULL && str->Ltag != THREAD)
{
str = str->leftchild; //当前驱不为1时,继续遍历左孩子
}
printf("%c ",str->data);
}
BiThrNode *next(BiThrNode *p) //后继
{
if (p == NULL) return NULL;
if (p->Rtag == THREAD)
{
return p->rightchild; //当后继为1时,返回右孩子
}
else
{
return frist(p->rightchild);
} //当后继不为1时,返回它的右孩子的前驱
}
InOrderThrTree(BiThrNode *str) //中序遍历线索二叉树
{
for (BtNode *p = frist(str);p != NULL;p = next(p))
{
printf("%c ",str->data); //前驱和后继
}
}
逆序中序遍历线索二叉树
堆排序
(ABCDEFG等等为需要排序的数字)
typedef int HeapElem;
还没有评论,来说两句吧...