⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erchashu2.c

📁 数据结构基础学习程序
💻 C
字号:
#define NULL 0;
#define maxsize 32
#include<stdio.h>
#include<malloc.h>
typedef char datatype;
typedef struct node
{
	datatype data;
	struct node *lchild, *rchild;
}bitree;


 
bitree *Q[maxsize];
bitree *CREATREE()   //xinjian yike erchashu
{
	char ch;
	int front,rear;
	bitree *root,*s;
	root=NULL;
	front=1;rear=0;
	ch=getchar();
	while(ch!='#')
	{
		s=NULL;
		if(ch!='@')
		{
			s=malloc(sizeof(bitree));
			s->data=ch;
			s->lchild=NULL;
			s->rchild=NULL;
		}
		rear++;
		Q[rear]=s;
		if(rear==1) root=s;
		else
		{
			if(s&&Q[front])
				if(rear%2==0) Q[front]->lchild=s;
			else
				Q[front]->rchild=s;
				if(rear%2==1) front++;
		}
		ch=getchar();
	}
	return root;
}/*CREATREE*/


INORDER(bitree *t)        //zhongxu bianli
{
	if (t)
	{
		INORDER(t->lchild);
		printf("\t%c\n",t->data);
		INORDER(t->rchild);
	}
}/*INORDER*/


int MAX(int a,int b)
{
	if (a>b) return (a);
	else return (b);
}/*MAX*/


int HIGH(bitree *t)
{
	if (t==0) return (0);
	else return (1+MAX(HIGH(t->lchild),HIGH(t->rchild)));
}


void main()
{
	bitree *root;
	printf("please input the leaves of the tree:\n");
	root=CREATREE();
	printf("zhong xu bian li shi:\n");
	INORDER(root);
	printf("high=%d\n",HIGH(root));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -