题目要求:
ex4_1:
1)二叉树结点类型定义为: typedefstructbnode { intdata; structbnode*lc,*rc; }bnode_type; 2)编写中序遍历函数; 3)编写后序遍历函数; 4)编写先序遍历函数; 5)编写create函数建立二叉排序树; 6)编写main()函数,先调用create函数,建立一颗二叉排序树;然后分别调用中序、后序、先序遍历函数,将二叉树的先序、中序和后序遍历序列输出到屏幕上。
程序如下:
#include <stdio.h>
#include <stdlib.h>
typedef struct bnode
{
int data;
struct bnode *lc, *rc;
}bnode_type;
bnode_type *create(void);
void preorder(bnode_type *root);
void inorder(bnode_type *root);
void postorder(bnode_type *root);
int main(void)
{
bnode_type *tree;
printf("Please input your datas(ended by -1):");
tree = create();
printf("Preorder:\n");
preorder(tree);
printf("\nInorder:\n");
inorder(tree);
printf("\nPostorder:\n");
postorder(tree);
printf("