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

二叉樹的幾種遍歷方式-創(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://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精品国产高清91久久久久久| 极品美女粉嫩啪啪高潮| 国产日本福利在线综合网| 日本成人精品一区二区三区| 亚洲淫婷婷久久一区二区| 91久久国产综合精品| 日韩免费的黄色片网站| 外国男人搞亚洲女人在线| 国产高清毛片区1区二区三区| 欧美精品成人免费在线| 国产一区 亚洲精品| 中文字幕变态另类一区二区| 色呦呦中文字幕在线播放| 日韩激情小视频在线观看| 99精品热视频在线观看| 综合激情网激情五月天| 亚洲天堂精品日韩电影| 丝袜美腿亚洲综合一区| 欧美日韩黄片免费在线观看| 国产一区二区三区午夜视频| 亚洲另类视频一区二区| 亚洲一区二区福利视频| 色婷婷一区二区三区网站| 色综合色狠狠天天综合色| 97资源在线公开视频| 欧洲亚洲精品免费二区| 91色综合久久久久婷婷| 朝桐光日韩一区二区三区| 国产看片色网站亚洲av| 高潮少妇水多毛多av| 亚洲欧美另类熟女丝袜| 九九九热精品在线视频观看| 一区二区三区四区毛片|