如何用C/C++实现根据表达式建立二叉树?
树的后序遍历
#include
#include
#include
#define NULL 0
struct BinaryTree
{
int data;
struct BinaryTree *lchild,*rchild;
}*BT;
int CreateTree(BinaryTree *a)
{
int num;
cout>num;
if(num==0) return 1;
else
{
a->data=num;
a->lchild=new BinaryTree;
if(CreateTree(a->lchild)) a->lchild=NULL;
a->rchild=new Bina...全部
树的后序遍历
#include
#include
#include
#define NULL 0
struct BinaryTree
{
int data;
struct BinaryTree *lchild,*rchild;
}*BT;
int CreateTree(BinaryTree *a)
{
int num;
cout>num;
if(num==0) return 1;
else
{
a->data=num;
a->lchild=new BinaryTree;
if(CreateTree(a->lchild)) a->lchild=NULL;
a->rchild=new BinaryTree;
if(CreateTree(a->rchild)) a->rchild=NULL;
return 0;
}
}
int PrintTree(int a)
{
if(a!=NULL)
{
coutlchild,PrintTree)) return 1;
else
{
if(PostOrder(a->rchild,PrintTree)) return 1;
else{ (*visit)(a->data); return 0;}
}
}
else return 0;
}
void main()
{
cout<<"Creating a new BinaryTree:"< 收起