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

📄 bitree.cpp

📁 王红梅编《数据结构》大多数的实验源码。内附详细的实验报告。
💻 CPP
字号:
#include "BiTree.h"

template <class T>
BiTree<T>::BiTree()
{
	root = Create(root);
}

template <class T>
BiNode<T> *BiTree<T>::Create(BiNode<T> *root)
{
	char ch;
	cin >> ch;
	if (ch == '#')
		return NULL;
	else
	{
		root		= new BiNode<T>;
		root->data	= ch;
		root->lchild	= Create(root->lchild);
		root->rchild	= Create(root->rchild);
		return root;
	}
}

template <class T>
void BiTree<T>::CountLeaf(int &count)
{
	CountLeaf(root, count);
}

template <class T>
void BiTree<T>::CountLeaf(BiNode<T> *root, int &count)
{
	if (root == NULL)
		return;
	if (root->lchild == NULL && root->rchild == NULL)
		count++;
	CountLeaf(root->lchild, count);
	CountLeaf(root->rchild, count);
}

template <class T>
void BiTree<T>::Release(BiNode<T> *root)
{
	if (root != NULL)
	{
		Release(root->lchild);
		Release(root->rchild);
		delete root;
	}
}

template <class T>
BiTree<T>::~BiTree()
{
	Release(root);
}

⌨️ 快捷键说明

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