数据结构-中序遍历线索二叉树,堆排序

来源:互联网 发布:我知女人心迅雷下载 编辑:程序博客网 时间:2024/06/15 08:21

线索化二叉树的定义

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等等为需要排序的数字)
二叉树转化为数组,序号符合左=2i+1,右=2i+2的规律

typedef int HeapElem;
阅读全文
0 0