数据结构—二叉树的建立,遍历,打印结果。数据结构—二叉树的建立,遍历,打印结果。
#include"stdio.h"
#include"malloc.h"
static long Count=0; #define Stack_Size 100 #define TRUE 1
#define FALSE 0
typedef struct Node
{
char data;
struct Node * lChild;
struct Node * rChild; }BiTNode,* BiTree;
typedef struct
{
Bi...
数据结构—二叉树的建立,遍历,打印结果。
#include"stdio.h"
#include"malloc.h"
static long Count=0; #define Stack_Size 100 #define TRUE 1
#define FALSE 0
typedef struct Node
{
char data;
struct Node * lChild;
struct Node * rChild; }BiTNode,* BiTree;
typedef struct
{
BiTree elem[Stack_Size];
int top;
}SeqStack;
void CreateBiTree(BiTree *bt) {
char ch;
ch=getchar();
if(ch=='#') *bt=NULL;
else
{
*bt=(BiTree)malloc(sizeof(BiTNode));
(*bt)->data=ch;
CreateBiTree(&((*bt)->lChild));
CreateBiTree(&((*bt)->rChild));
}
}
//ÏÈÐò?éÀúÊä?ö?þ?æÊ? void PreOrder(BiTree root) {
if(root!=NULL)
{
printf("%c",root->data);
PreOrder(root->lChild);
PreOrder(root->rChild);
}
}
void count(BiTree root) {
if(root!=NULL)
{
Count++;
PreOrder(root->lChild);
PreOrder(root->rChild);
}
}
//ÖÐÐò?éÀúÊä?ö?þ?æÊ?
void InOrder(BiTree root) {
if(root!=NULL)
{
InOrder(root->lChild);
printf("%c",root->data);
InOrder(root->rChild);
}
}
//ºóÐò?éÀúÊä?ö?þ?æÊ?
void PostOrder(BiTree root) {
if(root!=NULL)
{
PostOrder(root->lChild);
PostOrder(root->rChild);
printf("%c",root->data);
}
}
int PostTreeDepth(BiTree bt) {
int hl,hr,max;
if(bt!=NULL)
{
hl=PostTreeDepth(bt->lChild);
hr=PostTreeDepth(bt->rChild);
max=hl>hr? hl:hr;
return(max+1);
}
else return(0);
}
void main()
{int k,i;
long l=1;
BiTree bt;
printf("ÇëÊäÈë?âÊÔÊý?Ý?º");
CreateBiTree( &bt);
count(bt);
k=PostTreeDepth( bt);
for(i=0;i
本文档为【数据结构—二叉树的建立,遍历,打印结果。】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。