数据结构课程设计之-树与二叉树的转换(10)
时间:2026-01-19
时间:2026-01-19
副菜单选择:选择9继续操作 运用各种遍历形式遍历树
第 13 页 共 13 页
副菜单选择0结束程序
七.附录(源程序)
#include <stdio.h> #include <malloc.h> #include <stdlib.h> //设置常量:
#define MAX_TREE_SIZE 100
//一般树的存储结构有以下几种:双亲结点,孩子结点,孩子兄弟结点。本实验运用到的是双亲结点和孩子兄弟结点。具体存储结构如下: /*树的双亲表示结点结构定义*/ typedef struct {
int data;
int parent; //双亲位置域 }PTNode;
/*双亲表示法树结构*/ typedef struct {
PTNode node[MAX_TREE_SIZE];
int count; //根的位置和节点个数 }PTree;
/*树的孩子兄弟表示结点结构定义*/ typedef struct node{ int data; struct node *firstchild; struct node *rightsib; }BTNode,*BTree;
//初始化树(双亲表示法) void init_ptree(PTree *tree) {
tree->count=-1; }
//初始化树结点(孩子兄弟表示法) BTNode GetTreeNode(int x) { BTNode t; t.data=x; t.firstchild=t.rightsib=NULL; return t;
上一篇:人教版小学四年级下册语文期末试卷
下一篇:病理生理学问答题重点