5,530
社区成员
发帖
与我相关
我的任务
分享
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#include "string.h"
#include <iostream>
using namespace std;
struct tree;
typedef struct tree *Tree;
struct tree
{
char data;
Tree left;
Tree Right;
};
void CreatTree(Tree T)
{
char ch;
cin>>ch;
if(ch=='#')
return;
else
{
T=(Tree)malloc(sizeof(struct tree));
T->data=ch;
T->left=T->Right=NULL;
CreatTree(T->left);
CreatTree(T->Right);
}
}
void Print(Tree T)
{
while(T!=NULL)
{
printf("%c",T->data);
Print(T->left);
Print(T->Right);
}
}
int main()
{
Tree T=NULL;
CreatTree(T);
Print(T);
return 0;
}
#include<iostream>
using namespace std;
struct tree
{
char a;
tree *lchild,*rchild;
};
void set(tree *&b)
{
char ch;
cin>>ch;
if(ch=='#') return;
else
{
b=new tree;
b->a=ch;
b->lchild=b->rchild=NULL;
set(b->lchild);
set(b->rchild);
}
}
void print(tree *b)
{
if(b!=NULL)
{
cout<<b->a;
print(b->lchild);
print(b->rchild);
}
}
int main()
{
tree *b=NULL;
set(b);
print(b);
return 0;
}
void Print(Tree T)
{
while(T!=NULL)
{
printf("%c",T->data);
Print(T->left);
Print(T->Right);
}
}
void print(tree *b)
{
if(b!=NULL)
{
cout<<b->a;
print(b->lchild);
print(b->rchild);
}
}
struct tree;
typedef struct tree *Tree;
void print(tree *b)
{
if(b!=NULL)
{
cout<<b->a;
print(b->lchild);
print(b->rchild);
}
}
void print(Tree b)//注意看参数!!!!!!
{
if(b!=NULL)
{
cout<<b->a;
print(b->lchild);
print(b->rchild);
}
}