一.实验目的
(1)掌握二叉树的逻辑结构,遍历二叉树的非递归方法;
(2)熟悉掌握二叉链表存储二叉树的结点定义;
(3)掌握中序非递归遍历二叉树过程中栈的变化情况;
(4)学会利用递归方法建立二叉树;
(5)会编写中序遍历二叉树的非递归算法。
二.实验内容
编写程序,用先序递归的方法建立二叉树,建立二叉树后,用中序非递归方法遍历该
二叉树,并输出遍历序列。
三.源程序及主要算法说明
#
#include<stdio.h>
#include<stdlib.h>
#dene N 10
struct node
{
int data;
struct node *lch;
struct node *rch;
};
typedef struct node bitree;
typedef struct
{
bitree *elem[N];
int top;
}Stack;
Stack InitStack()
{
Stack S;
S.top=-1;
return(S);
}
void In_Bt(bitree *root)
{ bitree *Ss[10]; //定义栈数组