📄 3.cpp
字号:
#include<stdio.h>
#include<stdlib.h>
//#define n 20
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
struct BiTNode * createtree(struct BiTNode * *p ,char a1);
void treave(struct BiTNode *p);
void treave1(struct BiTNode *p);
void treave2(struct BiTNode *p);
void main()
{
char a1;
struct BiTNode * tree;
tree=NULL;
printf("\n\n\n\n\t\t *******************************************\n");
printf("\t\t *\t输入字符串:");
while(scanf("%c",&a1))
{
if(a1=='\n') break ;
createtree(&tree,a1);
}
printf("\n\n\n\t\t* \t中序输出:");
treave(tree);
printf("\n\n\n\t\t* \t前序输出:");
treave1(tree);
printf("\n\n\n\t\t* \t后序输出:");
treave2(tree);
printf("\n");
printf("\n\t\t *******************08.5.11*** make by gfc **\n");
getchar();
}
struct BiTNode * createtree(struct BiTNode * *p ,char a1)
{
if(*p==NULL)
{
*p=(struct BiTNode *)malloc(sizeof(struct BiTNode));
(*p)->data=a1;
(*p)->lchild=(*p)->rchild=NULL;
}
else if(a1<(*p)->data)
createtree(&(*p)->lchild,a1);
else createtree(&(*p)->rchild,a1);
return(*p);
}
void treave(struct BiTNode *p)
{
if(p!=NULL)
{
treave(p->lchild);
printf(" %c ",p->data);
treave(p->rchild);
}
}
void treave1(struct BiTNode *p)
{
if(p!=NULL)
{
printf(" %c ",p->data);
treave(p->lchild);
treave(p->rchild);
}
}
void treave2(struct BiTNode *p)
{
if(p!=NULL)
{
treave(p->lchild);
treave(p->rchild);
printf(" %c ",p->data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -