如何实现2-3-4树?

发布于 2024-12-17 08:04:29 字数 335 浏览 0 评论 0原文

删除了旧问题并写了一个更好的问题。所以我不知道该怎么做,所以我想我应该使用链表,但似乎会有限制。我注意到一些与树相关的包,例如 这些

这似乎也不符合我想要做的,然后我开始考虑使用 IsThere2NodesIsParentOf(x) 等方法为节点创建一个类,等等。我有点含糊,但我只是想知道我是否朝着正确的方向接近这个问题。

Deleted old question and wrote a better one. So I had no idea of how am I supposed to do this, so I thought I was supposed to use a linked list, but it seemed like there would be limitations. I noticed a few packages related to trees, such as these.

That also didn't seem to fit what I wanted to do, then I started thinking of creating a class for nodes with methods such as IsThere2Nodes or like IsParentOf(x), etc. I'm being a little vague, but I just want to know if I am I approaching this in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话难免假 2024-12-24 08:04:30

您绝对应该创建一个类来表示树的节点。

首先,考虑 2-3-4 树的定义。一个节点需要三个槽用于数据,四个槽用于子指针。它还需要某种指示来表明在任何特定时间有多少这些正在使用。这就是数据。然后需要对节点进行操作来支持对树的操作。根据您将对节点执行的操作来分析如何执行每个树操作,您应该能够全部弄清楚。

You definitely should be creating a class to represent a node of the tree.

To get going, consider the definition of a 2-3-4 tree. A node needs three slots for data and four slots for child pointers. It also needs some sort of indication of how many of these are in use at any particular time. That's the data. Then you need operations on nodes to support the operations on the tree. Analyze how to do each tree operation in terms of what you would do to the nodes and you should be able to figure it all out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文