在 B+ 树中代表孩子

问题描述

我正在构建一种 B+ Tree 类型,其中每个节点都有可以是另一个节点的子节点,或者 B+ Tree 的实际数据。在我的案例中,实际数据是 char*

我想知道我应该如何代表 B+ Tree 中的孩子。我是否应该存储一个 bool 标志来说明当前节点是否是叶子节点?

以下是一种方法

class Node
{
    size_t key[SIZE];     // Contains the keys of the node
    void* children[SIZE]; // An array of pointers,each one pointing to either another Node or a char*.
};

但是,我如何检查子项是 char*Node* 类型?我可以存储一个标志,但这会占用额外的内存。

模板呢?

template <class T>
class Node 
{
    size_t key[SIZE];   // Contains the keys of the node
    T* children[SIZE];
};

模板也能正常工作吗?我在某处读到你可以在编译时检查 childrenchar* 类型还是 Node* 类型,我认为没有任何额外的内存使用。

最好的方法是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)