#include <iostream>
using namespace std;
typedef int DATA;
struct SNode //除根结点之外的节点
{
DATA data;
SNode* pRight,*pLeft;
public:
SNode(DATA data):data(data)
{
pRight=pLeft=NULL;
}
};
struct SNode //除根结点之外的节点
{
DATA data;
SNode* pRight,*pLeft;
public:
SNode(DATA data):data(data)
{
pRight=pLeft=NULL;
}
};
SNode* g_pRoot=NULL;//在全局区定义一个跟节点
void PriOrder(SNode* p)//前序遍历函数,,,根左右
{
cout<<p->data<<endl;
getchar();
if(p->pLeft){PriOrder(p->pLeft);}
if(p->pRight){PriOrder(p->pRight);}
}
{
cout<<p->data<<endl;
getchar();
if(p->pLeft){PriOrder(p->pLeft);}
if(p->pRight){PriOrder(p->pRight);}
}
void PriOrder(SNode* p)//中序遍历函数,,,左根右
{if(p->pLeft){PriOrder(p->pLeft);}
cout<<p->data<<endl;
getchar();
{if(p->pLeft){PriOrder(p->pLeft);}
cout<<p->data<<endl;
getchar();
if(p->pRight){PriOrder(p->pRight);}
}
}
void PriOrder(SNode* p)//后序遍历函数,,,左右根
{if(p->pLeft){PriOrder(p->pLeft);}
if(p->pRight){PriOrder(p->pRight);}
cout<<p->data<<endl;
getchar();
{if(p->pLeft){PriOrder(p->pLeft);}
if(p->pRight){PriOrder(p->pRight);}
cout<<p->data<<endl;
getchar();
}
int main()
{
SNode* p=new SNode(3);//在堆上申请一个节点,里面的数据是3
g_pRoot=p;
int main()
{
SNode* p=new SNode(3);//在堆上申请一个节点,里面的数据是3
g_pRoot=p;
p->pLeft=new SNode(4);
p->pRight=new SNode(5);
p->pRight=new SNode(5);
//SNode* p1=p->pLeft;//p1指向左孩子了
#if 1
cout<<g_pRoot->data<<endl;
getchar();
#if 1
cout<<g_pRoot->data<<endl;
getchar();
PriOrder(g_pRoot);
#endif
return 0;
}
#endif
return 0;
}