tree23.h
来自「2-3树的数据结构以及演示程序」· C头文件 代码 · 共 64 行
H
64 行
#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 + =
减小字号Ctrl + -
显示快捷键?