線索二叉樹

2021-08-08 20:41:16 字數 1417 閱讀 9065

#include

#include

#include

typedef char elemtype;

typedef enumpointtag;

typedef struct bithrnode

;bithrnode * buy_node()

void  free_node(bithrnode *phead)

bithrnode *create_tree1()                      //二叉樹的建立

}bithrnode  *p = null;

void inorder(bithrnode *ptr)                          //給二叉樹加上索引

if (null!=p&&null == p->rightchild)             //沒有右孩子

p = ptr;

inorder(ptr->rightchild);}}

void  inorder_thr(bithrnode *ptr)                      //根據索引列印線索二叉樹

printf("%c ", p->data);

while (p->rtag == thread)

p = p->rightchild;}}

bithrnode* xianmake(bithrnode*root)//先序線索化二叉樹

if (p&& !p->rightchild)

p = root;

xianmake(root->leftchild);

xianmake(root->rightchild);

}return null;

}bithrnode* houmake(bithrnode*root)//後序線索化二叉樹

if (p && !p->rightchild)

p = root;

}return null;

}bithrnode *first(bithrnode *p)                                    

return p;

}bithrnode *next(bithrnode *p)

}void  inorder_thr(bithrnode *ptr)                           //列印線索二叉樹

printf("\n");

}bithrnode *last(bithrnode *p)                            //逆序列印線索二叉樹

return p;

}bithrnode *prev(bithrnode *p)

else

}void resthrinorder(bithrnode *ptr)

printf("\n");

}

線索二叉樹

當用二叉鍊錶作為二叉樹的儲存結構時,因為每個結點中只有指向其左 右兒子結點的指標,所以從任一結點出發只能直接找到該結點的左 右兒子。在一般情況下靠它無法直接找到該結點在某種遍歷序下的前驅和後繼結點。如果在每個結點中增加指向其前驅和後繼結點的指標,將降低儲存空間的效率。我們可以證明 在n個結點的二叉鍊...

線索二叉樹

1.線索二叉樹結構和操作定義 threadbintree.h 功能 線索標誌域所有值 typedef enumnodeflag 功能 線索二叉樹結構體 typedef struct threadtreethreadbintree 前驅節點指標 threadbintree previous null ...

線索二叉樹

原始碼 中序線索二叉樹 author 菜鳥 version 2014.7.23 include include include typedef char datatype using namespace std 定義線索二叉樹的結構體 typedef struct nodethreadbitreen...