文章
59
粉丝
0
获赞
340
访问
14.0k
#include <iostream>
using namespace std;
int pointer;
typedef struct BTNode{
int value;
struct BTNode *lc,*rc;
}BTNode,*BST;
void InsertTree(BST &T,int x)
{
if(T==NULL)
{
T=new BTNode;
T->value=x;
T->lc=NULL;
T->rc=NULL;
return;
}
if(T->value==x)
return;
else if(T->value>x)
InsertTree(T->lc,x);
else
InsertTree(T->rc,x);
}
void Preorder(BST T)
{
if(T)
{
cout<<T->value<<" ";
Preorder(T->lc);
Preorder(T->rc);
}
}
void Inorder(BST T)
{
if(T)
{
Inorder(T->lc);
cout<<T->value<<" ";
Inorder(T->rc);
}
}
void Postorder(BST T)
{
if(T)
{
Postorder(T->lc);
Postorder(T->rc);
cout<<T->value<<" ";
}
}
void DeleteTree(BST &T)
{
if(T)
{
DeleteTree(T->lc);
DeleteTree(T->rc);
delete T;
}
}
int main()
{
int n;
while(cin>>n)
{
BST T=NULL;
for(int i=0;i<n;...
登录后发布评论
暂无评论,来抢沙发