如何实现2-3-4树?
删除了旧问题并写了一个更好的问题。所以我不知道该怎么做,所以我想我应该使用链表,但似乎会有限制。我注意到一些与树相关的包,例如 这些。
这似乎也不符合我想要做的,然后我开始考虑使用 IsThere2Nodes
或 IsParentOf(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对应该创建一个类来表示树的节点。
首先,考虑 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.