二叉树结点路径求解源程序清单

二叉树结点路径求解源程序清单

ID:38654457

大小:47.50 KB

页数:10页

时间:2019-06-17

二叉树结点路径求解源程序清单_第1页
二叉树结点路径求解源程序清单_第2页
二叉树结点路径求解源程序清单_第3页
二叉树结点路径求解源程序清单_第4页
二叉树结点路径求解源程序清单_第5页
资源描述:

《二叉树结点路径求解源程序清单》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#include#include"1.h"#include"2.h"#include"3.h"voidmain(){BiTreeNode*root;MakeCharTree(root);cout<<"root树为:"<>buf;check(buf);path(root,buf);}………………………………………上述程序保存在主程序a.cpp中#i

2、nclude#includetemplateclassLinQueue;templateclassQueueNode{friendclassLinQueue;private:QueueNode*next;public:Tdata;QueueNode(constT&item,QueueNode*ptrNext=NULL){data=item;next=ptrNext;}~QueueNode(){};};templateclassLinQueue{private:Queue

3、Node*front;QueueNode*rear;intsize;public:LinQueue(void);~LinQueue(void);voidQInsert(constT&item);TQDelete(void);TQFront(void)const;intQueueEmpty(void)const{returnsize<=0;};voidClearQueue(void);intGetSize(void)const{returnsize;};};templateLinQueue::LinQueue(){front=rear=NULL;

4、size=0;}templateLinQueue::~LinQueue(void){ClearQueue();front=rear=NULL;}templatevoidLinQueue::QInsert(constT&item){QueueNode*newNode=newQueueNode(item,NULL);if(rear!=NULL)rear->next=newNode;rear=newNode;if(front==NULL)front=newNode;size++;}templateTLinQueu

5、e::QDelete(void){if(size==0){cout<<"队列已空无元素可删!"<*p=front->next;Tdata=front->data;deletefront;front=p;size--;returndata;}templateTLinQueue::QFront(void)const{returnfront->data;}templatevoidLinQueue::ClearQueue(void){QueueNode*p,*p1;p=fron

6、t;while(p!=NULL){p1=p;p=p->next;deletep1;}size=0;}……………………………………………以上程序保存在LinQueue.h中#include#includetemplateclassBiTreeNode{private:BiTreeNode*leftChild;//左子树指针BiTreeNode*rightChild;//右子树指针public:Tdata;//数据元素//构建函数和析构函数BiTreeNode():leftChild(NULL),rightCh

7、ild(NULL){};BiTreeNode(Titem,BiTreeNode*left=NULL,BiTreeNode*right=NULL):data(item),leftChild(left),rightChild(right){};~BiTreeNode(){};//结点操作的成员函数BiTreeNode*&Left(void)//返回值类型为指针的引用类型{returnleftChild;};BiTreeNode*&Right(void)//返回值类型为指针

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。