C++实现二叉树链表
Node.h
#ifndef NODE_H
#define NODE_H
#include <iostream>
using namespace std;
class Node
{
public:
Node();
~Node();
Node *SearchNode(int nodeIndex);
void DeleteNode();
void PreordeTraverse();
void InorderTraverse();
void PostorderTraverse();
int index;
int data;
Node *pLChild;
Node *pRChild;
Node *pParent;
private:
};
Node::Node()
{
index = 0;
data = 0;
pLChild = NULL;
pRChild = NULL;
pParent = NULL;
}
Node::~Node()
{
}
Node *Node::SearchNode(int nodeIndex)
{
Node *temp = NULL;
if (this->index == nodeIndex)
{
return this;
}
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
{
this->pRChild->SearchNode(nodeIndex);
if (temp != NULL)
{
return temp;
}
}
}
return