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

📄 binarytree.h

📁 家族树程序,实现家族树功能~数据结构实验~
💻 H
字号:
#include "BinaryNode.h"

template <class Entry>
class Binary_tree {
public:

Binary_node<Entry> *root;

Binary_tree()
{
    root = new Binary_node<Entry>();
}

Binary_tree(Entry data)
{
	root = new Binary_node<Entry>(data);
}

~Binary_tree()
{
	delete root;
	root = NULL;
}

void clear( )
{
	root = new Binary_node<Entry>();
}

bool empty() const
{
    return root->data == NULL;
}

void preorder(void (*visit)(Entry &))
{
	recursive_preorder(root, visit);
}

void postorder(void (*visit)(Entry &))
{
	recursive_postorder(root, visit);
}

private:

void recursive_preorder(Binary_node<Entry> *sub_root, void (*visit)(Entry &))
{
	if (sub_root != NULL)
	{
		visit(sub_root->data);
		for (int i = 0; i < TreeDegree; i++)
		{
			recursive_preorder(sub_root->children[i], visit);
		}
	}
}

void recursive_postorder(Binary_node<Entry> *sub_root, void (*visit)(Entry &))
{
	if (sub_root != NULL)
	{
		for (int i = 0; i < TreeDegree; i++)
		{
			recursive_preorder(sub_root->children[i], visit);
		}
		visit(sub_root->data);
	}
}

};

⌨️ 快捷键说明

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