标签:typedef char .com ace names order img tno stream
typedef struct BiTNode
{
char data;
struct BiTNode lchild,rchild;
}BTNode,*BTree;
void CreateTree(BTree &T)
{
char ch;
cin>>ch;
if(ch==‘#‘)
{
T=NULL;
}
else
{
T=(BTree) new BTNode;
if(!T)
exit(-1);
T->data=ch;
CreateTree(T->lchild);
CreateTree(T->rchild);
}
}
void PreOrder(BTree &T)
{
if(T)
{
cout<
PreOrder(T->lchild);
PreOrder(T->rchild);
}
}
void PreOrder(BTree &T)
{
if(T)
{
PreOrder(T->lchild);
cout<
PreOrder(T->rchild);
}
}
void PostOrder(BTree &T)
{
if(T!=NULL)
{
PostOrder(T->lchild);
PostOrder(T->rchild);
cout<
}
}
#include <stdlib.h>
#include
using namespace std;
typedef struct BiTNode
{
char data;
struct BiTNode lchild,rchild;
}BTNode,*BTree;
void CreateTree(BTree &T)
{
char ch;
cin>>ch;
if(ch==‘#‘)
{
T=NULL;
}
else
{
T=(BTree) new BTNode;
if(!T)
exit(-1);
T->data=ch;
CreateTree(T->lchild);
CreateTree(T->rchild);
}
}
void PreOrder(BTree &T)
{
if(T)
{
cout<
PreOrder(T->lchild);
PreOrder(T->rchild);
}
}
void InOrder(BTree &T)
{
if(T!=NULL)
{
InOrder(T->lchild);
cout<
InOrder(T->rchild);
}
void PostOrder(BTree &T)
{
if(T!=NULL)
{
PostOrder(T->lchild);
PostOrder(T->rchild);
cout<
}
}
int main()
{
BTree T;
cout<<"请输入树的节点:" ;
CreateTree(T);
cout<<"先序遍历:";
PreOrder(T) ;
cout<<endl;
cout<<"中序遍历:";
InOrder(T) ;
cout<<endl;
cout<<"后序遍历:";
PostOrder(T) ;
cout<<endl;
return 0;
}
abd##e##cf###
标签:typedef char .com ace names order img tno stream
原文地址:https://www.cnblogs.com/singly/p/10797682.html