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

📄 11þ-

📁 1、猴子选大王 2、约瑟夫环 3、迷宫求解 4、回文游戏 5、地图四染色问题 6、八皇后问题 7、原四则表达式求值 8、k阶斐波那契序列 9、遍历二叉树 10、编写DFS算法的非递归
💻
字号:
#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>


#define OVERFLOW 0
#define STACKSIZE 50
#define ADD	20


typedef struct CSNode
{
	char data;
	struct CSNode *firstchild;
	struct CSNode *nextsibling;		
}CSNode,* CSTree;


void CreateCSTree(CSTree &T)	//先序扩展序列建立树的递归算法 
{  
	char ch;
	scanf("%c",&ch);
	if (ch=='.') 
	{
		T=NULL;		
	}
	else 
	{ 
		if(!(T=(CSNode*)malloc(sizeof(CSNode))))
		{
			exit(OVERFLOW);
		}
		T->data=ch;
		CreateCSTree(T->firstchild); 
		CreateCSTree(T->nextsibling); 
	}  
} 

int Depth(CSTree T)//递归
{	int dep1,dep2;
	if(T==NULL)	return(0);
	else
	{	dep1=Depth(T->firstchild);//求第一个孩子子树的深度
		dep2=Depth(T->nextsibling);//求下一个兄弟子树的深度
		if(dep1+1>dep2) return(dep1+1);//树的深度为"max(左深+1,右深)"
		else return(dep2);
	}
}
void main()
{	CSTree T=NULL;
	printf("请输孩子兄弟法输入树,当子树为空时,用.来代替:\n");
			CreateCSTree(T); 
			if(T){
				printf("此树的深度为:");
				printf("%d",Depth(T));
				printf("\n");
			}
			else printf("树为空!\n");
}

⌨️ 快捷键说明

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