数据结构实验指导手册6

数据结构实验指导

实验六 二叉树的基本操作

一、实验目的

1、进一步掌握指针变量、动态变量的含义。

2、掌握二叉树的结构特性,以及各种存储结构的特点和适用范围。

3、掌握用指针类型描述、访问和处理二叉树的运算。

二、实验内容

1、以二叉链表作存储结构,试编写前序、中序、后序及层次顺序遍历二叉树的算法。 #define M 10

typedef int DataType;/*元素的数据类型*/

typedef struct node

{ DataType data;

struct node *lchild,*rchild;

}BitTNode,*BiTree;

int front=0,rear=0;

BitTNode *que[10];

BitTNode *creat()

{BitTNode *t;

DataType x;

scanf("%d",&x);

if(x==0) t=NULL;

else{ t=(BitTNode *)malloc(sizeof(BitTNode));

t->data=x;

t->lchild=creat();

t->rchild=creat();

}

return(t);

}/*creat*/

/* 前序遍历二叉树t */

void preorder(BiTree t)

{ if(t!=NULL)

{ printf("%4d",t->data);

preorder(t->lchild);

preorder(t->rchild);

}

}

/* 中序遍历二叉树t */

void inorder(BiTree t)

{ if(t!=NULL)

{ inorder(t->lchild);

你可能喜欢

  • 数据结构实验报告
  • 数据结构实验指导书
  • 数据结构实验作业
  • 数据结构综合实验
  • 数据结构排序算法实验
  • 数据结构试题及答案
  • 高频电子线路第五版
  • SQL2005

数据结构实验指导手册6相关文档

最新文档

返回顶部