資料結構演算法 二叉樹

2021-06-21 20:29:59 字數 1791 閱讀 5296

/**/

//    //

//   二叉樹資料結構  bintree.h       //

//    //

/**

#include

templateclass bintree;

template

class treenode

type data;

treenode *lchild;  //左,右子樹

treenode *rchild;

}; template

class bintree

void creattree();               //建立二叉樹,主過程

void creattree(treenode* child,int k); //子過程

void pretree(treenode*point);     //先序遍歷二叉樹

void inotree(treenode*point);  //中序遍歷二叉樹

void postree(treenode*point);  //後序遍歷二叉樹

void destroy(treenode*point);     //銷毀二叉樹

bool isempty();

protected:

treenode* root;

}; template

void bintree::creattree()

template

void bintree::creattree(treenode* child,int k)

char temp;

cout<<"該"cin>>temp;

if(temp=='y'||temp=='y')

cout<<"該"cin>>temp;

if(temp=='y'||temp=='y')

} template

void bintree::pretree(treenode*point)

} template

void bintree::inotree(treenode*point)

} template

void bintree::postree(treenode*point)

} template

bool bintree::isempty()

template

void bintree::destroy(treenode*point)

} /**//

//    //

//   二叉樹功能函式 bintree.cpp//

//    //

/**/

#include

#include"bintree.h"

const int int =13;

const double float= 13.33;

const char char ='a';

template

void bintree_creat(bintree& bintreeopp)

template

void bintree_pre(bintree& bintreeopp)

else

else

else

template

void bintreeini(type temp)

}while(true); }

void bintree()

}

資料結構 二叉樹 反轉二叉樹

include using namespace std define maxsize 1000 struct binary tree node class queue queue queue void queue push binary tree node btn binary tree node ...

《資料結構》 二叉樹

二叉樹 是 n個結點的有限集,它或為空集,或由乙個根結點及兩棵互不相交的 分別稱為該根的左子樹和右子樹的二叉樹組成。二叉樹不是樹的特殊情況,這是兩種不同的資料結構 它與無序樹和度為 2的有序樹不同。二叉樹的性質 1 二叉樹第 i層上的結點數最多為 2 i 1 2 深度為 k的二叉樹至多有 2 k 1...

資料結構 二叉樹

1.二叉樹 二叉樹是一種特殊結構的樹,每個節點中最多有兩個子節點,如圖1所示 圖1 二叉樹 在圖1中的二叉樹裡,a c有兩個子節點,b d有乙個子節點。對於二叉樹還有圖2中的以下情況 圖2 二叉樹的特殊情況 在博文中還介紹了滿二叉樹和完全二叉樹還有其他的特殊二叉樹。2.二叉樹的實現 有兩種實現方式,...