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

📄 tree23.h

📁 2-3树的数据结构以及演示程序
💻 H
字号:
#pragma once

#include ".\Tree23Node.h"

template <class TYPE>
class Tree23
{
protected:
	Tree23Node <TYPE> *root;				//2-3树的根结点
public:
	//构造函数
	Tree23 (Tree23Node <TYPE> *_root = NULL) {
		root = _root;
	}
	//析构函数
	void Destroy (void) {
		cout<<"Destructing Tree23"<<endl;
		root->DelTree();
		cout<<"Destructing Tree23 complete"<<endl;
	}
	//插入结点
	bool Insert(TYPE *data) {
		if (Search(data) != NULL) return false;

		Tree23Node <TYPE> *node = new Tree23Node <TYPE> (data);
		Tree23Node <TYPE> *temp;

		if (root == NULL) root = node;
		else {
			temp = root->InsertNode(node);
			if (temp != NULL) root = temp;
		}
		return true;
	}
	//打印所有结点
	void ShowAll() {
		root->ShowTree();
	}
	//搜索指定结点
	Tree23Node <TYPE> *Search(TYPE *d) {
		if (root == NULL) {
			//cout<<"root is NULL"<<endl;
			return NULL;
		}
		//cout<<"root is not NULL"<<endl;
		return root->Search(d);
		//return NULL;
	}
	//检验当前结点是否存在
	bool IsExisting(Tree23Node <TYPE> *node) {
		if (root == NULL) return false;
		if (root->Search(node) != NULL) return true;
		else return false;
	}
	//树型打印本树
	virtual void formatPrint() {
		if (root == NULL) {
			cout<<"目前是空树!"<<endl;
			return;
		}
		root->formatPrint(false, "");
	}
};

⌨️ 快捷键说明

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