文章
60
粉丝
361
获赞
43
访问
524.7k
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
typedef struct node
{
int data;
struct node *lchild,*rchild;
}*tree;
void paixu(tree &T,int temp)
{
if(T==NULL)
{
T=new node;
T->data=temp;
T->lchild =NULL;
T->rchild=NULL;
return;
}
else
{
if(temp==T->data)
return;
else if(temp<T->data)
paixu(T->lchild ,temp);
else if(temp>T->data)
paixu(T->rchild ,temp);
}
return;
}
void preorder(tree T)
{
if(T!=NULL)
{
cout<<T->data<<" " ;
preorder(T->lchild);
preorder(T->rchild);
}
}
void midorder(tree T)
{
if(T!=NULL)
{
midorder(T->lchild);
cout<<T->data<<" " ;
midorder(T->rchild);
}
}
void posorder(tree T)
{
if(T!=NULL)
{
posorder(T->lchild);
posorder(T->rchild);
cout<<T->data<<" " ;
}
}
int main()
{
int n;
int temp;
while(c...
登录后发布评论
暂无评论,来抢沙发