C 線索二叉樹

2021-04-17 08:26:46 字數 1141 閱讀 8082

using system;

namespace bithrtree

class bithrtree

else }

///

/// 線索化二叉樹:

///

///

static btnode pre,h;

static public void threading(ref btnode t)

static public void thread(ref btnode t)

else

if(t.rchild==null)

else

if(pre.rchild==null&&pre.rtag==0)pre.rchild=t;

pre=t;

if(t.ltag==1)thread(ref t.lchild);

if(t.rtag==1)thread(ref t.rchild);

} }

///

/// 先序輸出:

///

static public void preprint(btnode t) }

///

/// 先序線索遍歷輸出:

///

static public void prethrprint(btnode t) }

} }

///

/// deepth of a bithrtree:

///

static public int deepth(btnode t)

else }

static public int max(params int w) }

static void main()

",deepth(mytree));

btnode mytree2=null;

console.writeline("呼叫複製函式得到的新樹為:");

dulplicatebithrtree(mytree,ref mytree2);

preprint(mytree2);

console.readline();

console.readline();

} }

}

(C )二叉樹的線索化 線索二叉樹

線索化標誌tag enum pointertag 結點結構 template struct binarytreenodethd 基類迭代器 template struct binarytreeiterator t operator t operator bool operator const sel...

C 線索二叉樹

using system namespace bithrtree class bithrtree else 線索化二叉樹 static btnode pre,h static public void threading ref btnode t static public void thread r...

二叉樹 線索二叉樹(C )

由於傳統的二叉樹鍊錶儲存僅能體現一種父子關係,不能直接得到結點在遍歷中的前驅或後繼,於是引入了線索二叉樹。遍歷二叉樹是以一定的規則將二叉樹中的結點排列成乙個線性序列,從而得到幾種遍歷序列,使得該序列中的每個結點 第乙個和最後乙個結點除外 都有乙個直接前驅和直接後繼。引入線索二叉樹正是為了加快查詢結點...