实验内容:
1 输入字符序列,建立二叉链表。
2 按先序、中序和后序遍历二叉树(递归算法)。
3 按某种形式输出整棵二叉树。(逆时针打印二叉树)
4 求二叉树的高度。
5 求二叉树的叶节点个数。
6 交换二叉树的左右子树。
7 借助队列实现二叉树的层次遍历。
8 哈夫曼编码的实现(选作)
9 在主函数中设计一个简单的菜单,分别调试上述算法。代码:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include<stdio.h>
#include<stdlib.h>
#define M 100
typedef char Etype; //定义二叉树结点值的类型为字符型
typedef struct BiTNode //树结点结构
{
Etype data;
struct BiTNode *lch,*rch;
} BiTNode,*BiTree;
BiTree que[M];
int front=0,rear=0;
//函数原型声明
BiTNode *creat_bt1();
BiTNode *creat_bt2();
void preorder(BiTNode *p);
void inorder(BiTNode *p);
void postorder(BiTNode *p);
void enqueue(BiTree);
BiTree delqueue( );
void levorder(BiTree);
int treedepth(BiTree);
void prtbtree(BiTree,int);
void exchange(BiTree);
int leafcount(BiTree);
void paintleaf(BiTree);
BiTNode *t;
int count=0;
//主函数
int main()
{
//char ch;
int k;
do
{
printf("\n\n\n");
printf(