4.cpp
来自「约瑟夫环源代码,前中后序递归遍历二叉树」· C++ 代码 · 共 30 行
CPP
30 行
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define null 0
typedef struct node
{ char data;
node *lchild;
node *rchild;
}* bitree;
int setup(bitree &t)
{char ch=' ';
scanf("%c",&ch);
if(ch==' ')t=null;
else{
if(!(t=(node *)malloc(sizeof(node))))return 0;
t->data=ch; //建立根节点
printf("%c",t->data);
setup(t->lchild);//建立左子树
setup(t->rchild);//建立右子树
}
return 1;
}
void main()
{bitree t=null;
printf("输入数值:");
setup(t);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?