?? tree.h
字號:
//樹的孩子兄弟表示法為存儲結構的結構體Tree.h
template<class T> class Tree;
template<class T> struct TreeNode
{friend class Tree<T>;//樹類為友元
private:
TreeNode<T> *firstChild;//第一個孩子結點指針域
TreeNode<T> *nextSibling;//下一個兄弟結點指針域
public:
T data;//數據域
//構造函數
TreeNode(T value,TreeNode<T> *fc=NULL,
TreeNode<T> *ns=NULL):data(value),
firstChild(fc),nextSibling(ns){}
//訪問指針域的成員函數
TreeNode<T>* &FirstChild()
{return firstChild;}
TreeNode<T>* &NextSibling()
{return nextSibling;}
};
//樹類
template<class T> class Tree
{private:
TreeNode<T> *root;//根結點指針
TreeNode<T> *curr;//當前結點指針
//顯示以t為先根結點的樹的數據域
void PreOrderTree(TreeNode<T> *&t);
//顯示以t為后根結點的樹的數據域
void PosOrderTree(TreeNode<T> *&t);
//使當前結點為t所指結點
int Current(TreeNode<T> *&t);
//在樹root中回溯查找結點s的雙親結點
TreeNode<T> *SearchParent(TreeNode<T> *&root,TreeNode<T> *&s);
public:
//構造函數與析構函數
Tree(){root=curr=NULL;}
~Tree(){DeleteSubTree(root);}
//使根結點為當前結點
int Root();
//使當前結點的雙親結點為當前結點
int Parent();
//使當前結點的第一個孩子結點為當前結點
int FirstChild();
//使當前結點的兄弟結點為當前結點
int NextSibling();
//把valve插入到當前結點的最后一個結點
void InsertChild(T value);
//刪除以t為根結點的子樹
void DeleteSubTree(TreeNode<T> *&t);
//刪除當前結點的第i個孩子結點
int DeleteChild(int i);
//刪除以root為根結點的子樹的第i個孩子結點
int DeleteChild1(int i);
//按先根遍歷次序顯示樹的數據域值
void DisplayTree();
//按后根遍歷次序顯示樹的數據域值
void DisplayTree1();
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -