#include "Node.h"
#include <iostream>
using namespace std;
Node::Node(){
index = 0;
data = 0;
pLChild = NULL;
pRChild = NULL;
}
Node* Node::searchNode(int nodeIndex){
if(this->index == nodeIndex)
return this;
Node *temp = NULL;
if(this->pLChild != NULL){
if(this->pLChild->index == nodeIndex)
return this->pLChild;
else{
temp = this->pLChild->searchNode(nodeIndex);
if(temp != NULL){ /**在左孩子中找到了要找的节点返回,没找到不返回,继续寻找右孩子**/
return temp;
}
}
}
if(this->pRChild != NULL){
if(this->pRChild->index == nodeIndex)
return this->pRChild;
else{
temp = this->pRChild->searchNode(nodeIndex);
return temp;
}
}
return NULL;
}
void Node::delNode(){
if(this->pLChild != NULL)
this->pLChild->delNode();
if(this->pRChild != NULL)
this->pRChild->delNode();
/****/
if(this->pParent != NULL){
if(this->pParent->pLChild == this)
this->pParent->pLChild = NULL;
if(this->pParent->pRChild == this)
this->pParent->pRChild = NULL;
}
delete this;
}
void Node::preOrderTraverse(){
cout<<this->index<<" "<<this->data<<endl;
if(this->pLChild != NULL)
this->pLChild->preOrderTraverse();
if(this->pRChild != NULL)
this->pRChild->preOrderTraverse();
}
void Node::midOrderTraverse(){
if(this->pLChild != NULL)
this->pLChild->midOrderTraverse();
cout<<this->index<<" "<<this->data<<endl;
if(this->pRChild != NULL)
this->pRChild->midOrderTraverse();
}
void Node::postOrderTraverse(){
if(this->pLChild != NULL)
this->pLChild->postOrderTraverse();
if(this->pRChild != NULL)
this->pRChild->postOrderTraverse();
cout<<this->index<<" "<<this->data<<endl;
}
使用C++链表实现二叉树的存储及基本操作
需积分: 50 115 浏览量
2016-10-06
22:50:28
上传
评论 4
收藏 2KB RAR 举报
Lavi_qq_2910138025
- 粉丝: 1387
- 资源: 28
最新资源
- 毕业设计- 基于STM32F103C8T6 单片机,物联网技术的太阳能发电装置+源代码+文档说明+架构图+界面截图
- 基于 LSTM(长短期记忆)(即改进的循环神经网络)预测风力发电厂中风力涡轮机产生的功率+源代码+文档说明
- 基于stm32f103+空心杯电机+oled按键+运动算法
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈