//很久以前自己整理的代码,也有部分参考了网络上前辈的经验
#include <stdio.h>
#include <stdlib.h>
#define OVERFLOW -2
#define OK 1
#define ERROR 0
#define MAX 100
#include <math.h>
#include <windows.h>
//typedef enum { Link, Thread } PointerThr; // Link==0:指针,Thread==1:线索
typedef struct BiThrNode{
int data;
struct BiThrNode *lchild, *rchild; // 左右指针
int LTag, RTag; // 左右标志
} BiThrNode, *BiThrTree;
typedef struct QNode
{
BiThrNode *data;
struct QNode *next;
}QNode, *QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
//以下为队列操作,用于层序遍历输出树形结构
//构造一个空队列Q
int InitQueue(LinkQueue &Q)
{
Q.front = Q.rear = (QNode *)malloc(sizeof(QNode));
if(!Q.front)
return 0;
Q.front->next = NULL;
return OK;
}
//进队操作函数
int EnQueue(LinkQueue &Q, BiThrNode *e)
{
QNode *p;
p = (QNode *)malloc(sizeof(QNode));
if(!p)
return 0;
p->data = e;
p->next = NULL;
Q.rear->next = p;
Q.rear = p;
return OK;
}
//出队操作
BiThrNode * DeQueue(LinkQueue &Q)
{
QNode *p;
BiThrNode *e;
if(Q.front == Q.rear)
return NULL;
p = Q.front->next;
e = p->data;
Q.front->next = p->next;
if(Q.rear == p)
Q.rear = Q.front;
free(p);
return e;
}
//二叉树深度
int FindDepth(BiThrTree pRoot)
{
if(pRoot == NULL)
二叉树遍历线索化及树形结构输出
最新推荐文章于 2022-07-14 16:23:03 发布