欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

二叉樹的幾種遍歷方式-創(chuàng)新互聯(lián)

#include
#include
#include
using namespace std;
template
class BinaryTreeNode {
?private:
??? ?T element;
??? ?BinaryTreeNode*leftChild;
??? ?BinaryTreeNode*rightChild;
?public:
??? ?BinaryTreeNode() {};
??? ?BinaryTreeNode(const T& ele):element(ele),leftChild(NULL),rightChild(NULL) {};
??? ?BinaryTreeNode(const T& ele,BinaryTreeNode*l,BinaryTreeNode*r);
??? ?BinaryTreeNode* getLeftChild()const {
??? ??? ?return leftChild;
??? ?};
??? ?BinaryTreeNode* getRightChild()const {
??? ??? ?return rightChild;
??? ?};
??? ?void setLeftChild(BinaryTreeNode*l) {
??? ??? ?leftChild=l;
??? ?};
??? ?void setRightChild(BinaryTreeNode*r) {
??? ??? ?rightChild=r;
??? ?};
??? ?void createLeftChild();
??? ?void createRightChild();
??? ?T getvalue() const {
??? ??? ?return element;
??? ?};
??? ?void setvalue(const T& val) {
??? ??? ?element=val;
??? ?};
??? ?bool isLeaf()const;
};
template
class BinaryTree {

創(chuàng)新互聯(lián)的客戶來自各行各業(yè),為了共同目標,我們在工作上密切配合,從創(chuàng)業(yè)型小企業(yè)到企事業(yè)單位,感謝他們對我們的要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。專業(yè)領域包括成都網(wǎng)站設計、成都網(wǎng)站建設、電商網(wǎng)站開發(fā)、微信營銷、系統(tǒng)平臺開發(fā)。

?public:
??? ?BinaryTreeNode* root;
??? ?BinaryTree();
??? ?BinaryTree(BinaryTreeNode*a):root(a) {
??? ?};
??? ?bool isEmpty() const;
??? ?BinaryTreeNode* getRoot() {
??? ??? ?return root;
??? ?};
??? ?BinaryTreeNode* getparent(BinaryTreeNode* current)const;
??? ?BinaryTreeNode* getLeftsibling(BinaryTreeNode* current)const;
??? ?void levelOrder(BinaryTreeNode*root);
??? ?void preOrder(BinaryTreeNode*root);
??? ?void PreOrderWithoutRecursion(BinaryTreeNode*root);
??? ?void inOrder(BinaryTreeNode*root);
??? ?void InOrderWithoutRecursion(BinaryTreeNode*root);
??? ?void postorder(BinaryTreeNode*root);
??? ?void PostOrderWithoutRecursion(BinaryTreeNode*root);
??? ?void visit(BinaryTreeNode* t);
??? ?void PreInBuild(T* a,T* b,int num);
??? ?void Getroot(BinaryTreeNode*a);
??? ?void maketree(BinaryTree* b1,BinaryTree* b2);
};
template
void BinaryTree::Getroot(BinaryTreeNode*a) {
?root=a;
}
template
void BinaryTree::maketree(BinaryTree* b1,BinaryTree* b2) {
?this->root->setLeftChild(b1->getRoot());
?this->root->setRightChild(b2->getRoot());
}
template
void BinaryTree::levelOrder(BinaryTreeNode*root) {
?queue*>nodeQueue;
?BinaryTreeNode*pointer=root;
?if(pointer)
??? ?nodeQueue.push(pointer);
?while(!nodeQueue.empty() ) {
??? ?pointer=nodeQueue.front();
??? ?visit(pointer);
??? ?nodeQueue.pop();
??? ?if(pointer->getLeftChild())
??? ??? ?nodeQueue.push(pointer->getLeftChild());
??? ?if(pointer->getRightChild())
??? ??? ?nodeQueue.push(pointer->getRightChild());
?}
}
template
void BinaryTree::preOrder(BinaryTreeNode*root) {
?if(root!=NULL) {
??? ?visit(root);
??? ?preOrder(root->getLeftChild());
??? ?preOrder(root->getRightChild());
?}
}
template
void BinaryTree::PreOrderWithoutRecursion(BinaryTreeNode*root) {
?stack*>nodeStack;
?BinaryTreeNode*pointer=root;
?while(!nodeStack.empty()||pointer) {
??? ?if(pointer) {
??? ??? ?visit(pointer);
??? ??? ?if(pointer->getRightChild()!=NULL)
??? ??? ??? ?nodeStack.push(pointer->getRightChild());
??? ??? ?pointer=pointer->getLeftChild();
??? ?} else {
??? ??? ?pointer=nodeStack.top();
??? ??? ?nodeStack.pop();
??? ?}
?}
}
template
void BinaryTree::inOrder(BinaryTreeNode*root) {
?if(root!=NULL) {
??? ?inOrder(root->getLeftChild());
??? ?visit(root);
??? ?inOrder(root->getRightChild());
?}
}
template
void BinaryTree::InOrderWithoutRecursion(BinaryTreeNode*root) {
?stack*>nodeStack;
?BinaryTreeNode*pointer = root;
?while(!nodeStack.empty() ||pointer) {
??? ?if(pointer) {
??? ??? ?nodeStack.push(pointer);
??? ??? ?pointer = pointer->getLeftChild();
??? ?} else {
??? ??? ?pointer= nodeStack.top();
??? ??? ?visit(pointer);
??? ??? ?pointer= pointer->getRightChild();
??? ??? ?nodeStack.pop();
??? ?}
?}
}
template
void BinaryTree::postorder(BinaryTreeNode*root) {
?if(root!=NULL) {
??? ?postorder(root->getLeftChild());
??? ?postorder(root->getRightChild());
??? ?visit(root);
?}
}
template
void BinaryTree::PostOrderWithoutRecursion(BinaryTreeNode*root) {
?stack* >nodeStack;
?BinaryTreeNode*pointer =root;
?BinaryTreeNode*pre =root;
?while(pointer) {
??? ?for(; pointer->getLeftChild() != NULL; pointer = pointer->getLeftChild())
??? ??? ?nodeStack.push (pointer);
??? ?while(pointer != NULL && (pointer->getRightChild() == NULL || pointer->getRightChild() == pre)) {
??? ??? ?visit(pointer);
??? ??? ?pre = pointer;
??? ??? ?if(nodeStack.empty())
??? ??? ??? ?return;
??? ??? ?pointer = nodeStack.top();
??? ??? ?nodeStack.pop();
??? ?}
??? ?nodeStack.push(pointer);
??? ?pointer = pointer->getRightChild();
?}
}
template
void BinaryTree::visit(BinaryTreeNode* t) {
?cout<getvalue()<<" ";
}
template
void BinaryTree::PreInBuild(T* pre,T* in,int num) {
}
int main() {
?BinaryTreeNode*x=new ?BinaryTreeNode(1);
?BinaryTreeNode*s=new ?BinaryTreeNode(4);
?BinaryTreeNode*t=new ?BinaryTreeNode(5);
?BinaryTreeNode*r=new ?BinaryTreeNode(2);
?r->setRightChild(t);
?r->setLeftChild(s);
?BinaryTreeNode*u=new ?BinaryTreeNode(3);
?BinaryTreeNode*v=new ?BinaryTreeNode(6);
?u->setRightChild(v);
?BinaryTree* b1=new BinaryTree(r);
?BinaryTree* b2=new BinaryTree(u);
?BinaryTree* b3=new BinaryTree(x);
?b3->maketree(b1,b2);
?cout<<"廣度優(yōu)先 ?:";?
?b3->levelOrder(x);
?cout< ?cout<<"前序遞歸 ?:";
?b3->preOrder(x);
?cout< ?cout<<"前序非遞歸:";
?b3->PreOrderWithoutRecursion(x);
?cout< ?cout<<"中序遞歸 ?:";?
?b3->inOrder(x);
?cout< ?cout<<"中序非遞歸:";
?b3->InOrderWithoutRecursion(x);
?cout< ?cout<<"后序遞歸 ?:";
?b3->postorder(x);
?cout< ?cout<<"后序非遞歸:";
?b3->PostOrderWithoutRecursion(x);
}

你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)頁題目:二叉樹的幾種遍歷方式-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.aaarwkj.com/article32/gohpc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、手機網(wǎng)站建設、網(wǎng)頁設計公司、網(wǎng)站建設、外貿(mào)網(wǎng)站建設、網(wǎng)站內(nèi)鏈

廣告

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

成都app開發(fā)公司
91精彩啦在线看国产| 日本中文字幕在线一区| 亚洲永久免费黄色av| 背德人妻中文字幕无修| 日本成人午夜在线观看| 日韩av在线播放亚洲天堂| 人妻有码系列中文字幕专区| 女人被爽到高潮呻吟免费看| 香蕉视频网站欧美一区| 男人天堂av东京热伊人| 国产三级精品三级专区| 国产三级传媒在线观看| 视频一区二区三区拍拍| 91嫩草中文字幕在线| 天堂av在线网址观看| 日韩欧美二区三区精品在线| 欧美日韩综合在线第一页| 国产亚洲av一区二区三区| 欧美日韩国产激情在线观看| 日韩少妇一级淫片免费| 我要看国产一级内射片| 四虎国产精品久久久久久网址| 蜜臀av在线播放黑丝| 久久人热视频这里只有精品| 日韩欧美国产精品自拍| 少妇互射视频免费视频| 中文字幕人妻丝乱一区三区| 亚洲国产欲色有一二欲色| 欧美另类亚洲日本一区二区| 国产精品熟女在线视频| 麻豆av久久一区二区| 久久国产精品久久国产精品| 亚欧成人永久免费视频| 日本免费91午夜视频| 中文字幕人妻系列东京热| 亚洲国产成人综合一区二区三区| 性生活自制视频网站麻豆| 人妻少妇一区二区三区四区| 久久re这里只有精品6| 欧美黄片视频在线免费看| 亚洲毛片一区二区在线|