99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

遞歸實(shí)現(xiàn)二叉樹(shù)

對(duì)于二叉樹(shù)的實(shí)現(xiàn)主要運(yùn)用遞歸進(jìn)行實(shí)現(xiàn),代碼如下:

創(chuàng)新互聯(lián)公司專(zhuān)注于昌吉企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站開(kāi)發(fā)。昌吉網(wǎng)站建設(shè)公司,為昌吉等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站設(shè)計(jì),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)

#include <assert.h>

template<class T>

struct BinaryTreeNode

{

T _data;

BinaryTreeNode<T> *_left;

BinaryTreeNode<T> *_right;

BinaryTreeNode(const T&x)

:_data(x)

, _left(NULL)

, _right(NULL)

{}

};

template <class T>

class BinaryTree

{

protected:

BinaryTreeNode<T> *_root;

BinaryTreeNode<T> *_creattree(const T a[], size_t size, size_t &index, T invalid)

{

BinaryTreeNode<T> * root = NULL;

if (index < size && a[index] != invalid)

{

root = new BinaryTreeNode<T>(a[index]);

root->_left = _creattree(a, size, ++index, invalid);

root->_right = _creattree(a, size, ++index, invalid);

}

return root;

}

void _prevorder(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return;

cout << root->_data << " ";

_prevorder(root->_left);

_prevorder(root->_right);*/

}

void _inorder(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return;

_inorder(root->_left);

cout << root->_data<<" ";

_inorder(root->_right);

}

void _postorder(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return;

_postorder(root->_left);

_postorder(root->_right);

cout << root->_data << " ";

}

size_t  _leafsize(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return 0;

if (root->_left == NULL && root->_right == NULL)

return 1;

return _leafsize(root->_left) + _leafsize(root->_right);

}

size_t _size(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return 0;

return _size(root->_left) + _size(root->_right) + 1;

}

size_t _Depth(const BinaryTreeNode<T> *root)

{

if (root == NULL)

return 0;

int left = _Depth(root->_left);

int right = _Depth(root->_right);

return left > right ? left + 1 : right + 1;

}

public:

BinaryTree(T const*a = "", size_t size = 0)

{

size_t index = 0;

_root = _creattree(a, size, index, '#');

}

void prevorder()

{

_prevorder(_root);

}

void inorder()

{

_inorder(_root);

}

void postorder()

{

_postorder(_root);

}

size_t size()

{

int count = _size(_root);

return count;

}

size_t leafsize()

{

int count = _leafsize(_root);

return count;

}

size_t Depth()

{

int depth = _Depth(_root);

return depth;

}

};

void test()

{

BinaryTree<char> b("12#3##45#6#7##8", 15);

/*b.levelorder();*/

/*BinaryTree<char> b1;

b1 = b;*/

/*cout<<b.Depth();*/

/*cout << b.size();*/

b.postorder();

/*cout << b.leafsize();*/

}

int main()

{

test();

getchar();

return 0;

}

標(biāo)題名稱(chēng):遞歸實(shí)現(xiàn)二叉樹(shù)
文章轉(zhuǎn)載:http://www.yijiale78.com/article38/joospp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、服務(wù)器托管、網(wǎng)站維護(hù)、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)小程序開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)