-
实
验
报
告
题目:
二叉树的遍历及应用
院系:
数学系
专业:
数学与应用数学
学号:
2010114036
姓名:
郭奇瑞
一、
实验名称:二叉树的遍历及应用
二、
实验日期:
2012
年
11
月
14
日
三、
实验要求:编程实现二叉树的建立并对其进行遍历
四、
实验目的:
1
、
掌握二叉树链式存储结构的类型定义及实现;
2
、
掌握二叉树链式存储结构的各类基本运算方法;
3
、
掌握二叉树各个重要性质在解决实际问题中的应用;
4
、
掌握二叉树的分析方法、解决方法,从而提高实际编程能
力及程序调试能力。
五、
实验内容
1
、
创建二叉树;
2
、
用递归方法实现二叉树的各种遍历。
六、
程序代码
#include
#include
#define TRUE 1
#define FALSE 0
#define Stack_Size 50
typedef struct Node
{
char data;
struct Node *LChild;
struct Node *RChild;
}BiTNode,*BiTree;
typedef BiTree StackElementType;
typedef struct
{
StackElementType elem[Stack_Size];
int top;
}SeqStack;
//
初始化
void InitStack(SeqStack *S)
{
S->top=-1;
}
//
进栈
int Push(SeqStack *S,StackElementType x)
{ if(S->top==Stack_Size-1) return(FALSE);
S->top++;
S->elem[S->top]=x;
return(TRUE);
}
//
出栈
int Pop(SeqStack *S,StackElementType *x)
{
if(S->top==-1)
return(FALSE);
else
{
*x=S->elem[S->top];
S->top--;
return(TRUE);
}
}
//
先序遍历
void PreOrder(BiTree root)
{
if(root!=NULL)
{
printf(
PreOrder(root->LChild);
-
-
-
-
-
-
-
-
本文更新与2021-01-25 09:42,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/565151.html