Java 排序双向链表
我在这里遇到了一个问题,实现名字和姓氏的排序双向链接列表。
向每个链接添加一个字段,指示按字母顺序排列的下一个名字;现有的下一个链接用于指示按字母顺序排列的下一个姓氏。您还需要该列表的第二个根链接 - 现有的根链接指示按字母顺序排列的第一个姓氏,并且您将需要一个指示按字母顺序排列的第一个名字的根链接。请注意,对于列表中输入的每个名称,您仍然只有一个链接对象。
完成此操作后,对插入、查找和删除方法进行必要的更改,以便维护两个交错列表。还要根据需要更新运行时间估计以保持准确。
最后,添加第二个查找方法,该方法接受名字并返回包括该名字的所有全名,以及第二个显示方法,按名字的字母顺序打印姓名列表。确保您也给出了这些方法的运行时间估计。
我完全不知道如何做到这一点。我已经创建了一个带有名字和姓氏的链接列表,但这只是我所能得到的。
任何帮助都会很棒:D
谢谢。
I got a problem here, implementing a Sorted Doubly Linked List of first and last names.
Add a field to each link that indicates the alphabetically next first name; the existing next link is used to indicate the alphabetically next last name. You will also need a second root link for the list - the existing root link indicates the alphabetically first last name, and you will need one indicating the alphabetically first first name. Note that you will still only have one link object for each name entered in the list.
Having done this, make any necessary changes to your insert, lookup, and delete methods so that both interleaved lists are maintained. Also update the runtime estimates as required to remain accurate.
Finally, add a second lookup method that takes in a first name and returns all full names including that first name, and a second display method that prints the list of names out alphabetically by first name. Make sure you give runtime estimates for these methods as well.
And I am at a complete loss as how to do this. I already created a single linked list, with a first and last name, but that's as far as I was able to get.
Any Help would be great :D
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这确实很像家庭作业:)
This does smell a lot like homework :)
因为您已经实现了单链表,所以扩展到双向链表应该不会太困难。您已经有了后续的参考资料(见下图)。现在您还需要添加向后引用。另外,请注意下图中的蓝色线条。添加拼写属性的附加参考。因此每个节点都将具有变量:
Because you have already implemented a Singly Linked List, expanding to a doubly linked list shouldn't be too difficult. You already have references going forward (see picture below). Now you need to add references going backward as well. In addition, note the blue lines in the picture below. Add additional references for the spelling properties. So each node will have the variables:
您不需要向后引用!该任务需要类似 2 个单链表的东西,它们使用相同的对象作为条目。每个对象都有两个链接:一个链接到列表 A 中的下一项,一个链接到列表 B 中的下一项。
You do NOT need backward-references! The task asks for something like 2 single-linked Lists, that use the same objects as entrys. Every object has two links: one to the next item in list A, and one to the next item in list B.