nefu树
–题目来源
7075
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
}tree;
void creattree(tree* &t)
{
char ch;
cin>>ch;
if(ch=='@')
t=NULL;
else
{
t=new tree;
t->data=ch;
creattree(t->lchild);
creattree(t->rchild);
}
}
int showtree(tree* &t)
{
if(t!=NULL)
{
showtree(t->lchild);
showtree(t->rchild);
char c;
c=t->data;
cout<<c;
}
else
return 1;
}
int main()
{
tree *t;
creattree(t);
showtree(t);
return 0;
}
7078
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
int ltag,rtag;
}nodetree,*tree;
tree pre=NULL;
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
void connecttree(tree &t)
{
if(t)
{
connecttree(t->lchild);
if(t->lchild!=NULL)
{
t->ltag=0;
}
else
{
t->ltag=1;
t->lchild=pre;
}
if(pre!=NULL)
{
if(pre->rchild!=NULL)
{
t->rtag=0;
}
else
{
pre->rtag=1;
pre->rchild=t;
}
}
pre=t;
connecttree(t->rchild);
}
}
void showtree(tree &t)
{
tree p;
p=t;
while(p!=NULL)
{
while(p->ltag==0)
p=p->lchild;
cout<<p->data;
while(p->rtag==1&&p->rchild!=NULL)
{
p=p->rchild;
cout<<p->data;
}
p=p->rchild;
}
}
void show(tree &t)
{
if(t!=NULL)
{
show(t->lchild);
printf("%c",t->data);
show(t->rchild);
}
}
int main()
{
tree t;
createtree(t);
connecttree(t);
showtree(t);
//show(t);
return 0;
}
7079
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
int ltag,rtag;
}nodetree,*tree;
tree pre=NULL;
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
void show(tree &t)
{
int i;
tree p,s[10];
p=t;
i=0;
if(t==NULL)
return;
do
{
while(p!=NULL)
{
s[i]=p;
i++;
p=p->lchild;
}
if(i>0)
{
i--;
p=s[i];
printf("%c",p->data);
p=p->rchild;
}
}
while(i>0||p!=NULL);
}
int main()
{
tree t;
createtree(t);
show(t);
return 0;
}
7077
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
int ltag,rtag;
}nodetree,*tree;
typedef struct Node {
tree data;
struct Node *next;
}Node, *pNode;
pNode p;
void InitQueue()
{
p = (struct Node *)malloc(sizeof(struct Node));
p->next = p;
}
void EnQueue(tree x)
{
pNode r,t=p;
r = (struct Node *)malloc(sizeof(struct Node));
r->data=x;
while(t->next!=p)
{
t=t->next;
}
t->next=r;
r->next=p;
}
int isEmpty()
{
if(p->next==p)
return 1;
else
return 0;
}
void DeQueue(tree &x)
{
pNode t=p->next;
x=t->data;
p->next=t->next;
free(t);
}
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
void show(tree &t)
{
InitQueue();
EnQueue(t);
tree x;
while(!isEmpty())
{
DeQueue(x);
printf("%c",x->data);
if(x->lchild!=NULL)
EnQueue(x->lchild);
if(x->rchild!=NULL)
EnQueue(x->rchild);
}
}
int main()
{
tree t;
createtree(t);
show(t);
return 0;
}
7076
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
}nodetree,*tree;
int i;
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
void show(tree &t)
{
if(t!=NULL)
{
if(t->lchild==NULL&&t->rchild==NULL)
i++;
show(t->lchild);
show(t->rchild);
}
}
int main()
{
tree t;
createtree(t);
show(t);
cout<<i;
return 0;
}
7074
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
}nodetree,*tree;
int maxdeep=0;
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
int max1(int a,int b)
{
if(a>b)
return a;
else
return b;
}
void deep(tree t,int nowdeep)
{
if(t!=NULL)
{
maxdeep=max1(maxdeep,nowdeep);
deep(t->lchild,nowdeep+1);
deep(t->rchild,nowdeep+1);
}
}
int main()
{
tree t;
createtree(t);
deep(t,1);
cout<<maxdeep;
return 0;
}
7080
#include <iostream>
using namespace std;
typedef struct tree1{
char data;
struct tree1 *lchild,*rchild;
}nodetree,*tree;
int i;
void createtree(tree &t)
{
char ch;
cin>>ch;
if(ch!='@')
{
t=new nodetree;
t->data=ch;
createtree(t->lchild);
createtree(t->rchild);
}
else
t=NULL;
}
void show(tree &t)
{
if(t!=NULL)
{
if(t->lchild==NULL)
i++;
show(t->lchild);
show(t->rchild);
}
}
int main()
{
tree t;
createtree(t);
show(t);
cout<<i;
return 0;
}