Java 排序双向链表

发布于 2024-10-21 02:15:09 字数 471 浏览 3 评论 0原文

我在这里遇到了一个问题,实现名字和姓氏的排序双向链接列表。

向每个链接添加一个字段,指示按字母顺序排列的下一个名字;现有的下一个链接用于指示按字母顺序排列的下一个姓氏。您还需要该列表的第二个根链接 - 现有的根链接指示按字母顺序排列的第一个姓氏,并且您将需要一个指示按字母顺序排列的第一个名字的根链接。请注意,对于列表中输入的每个名称,您仍然只有一个链接对象。

完成此操作后,对插入、查找和删除方法进行必要的更改,以便维护两个交错列表。还要根据需要更新运行时间估计以保持准确。

最后,添加第二个查找方法,该方法接受名字并返回包括该名字的所有全名,以及第二个显示方法,按名字的字母顺序打印姓名列表。确保您也给出了这些方法的运行时间估计。

我完全不知道如何做到这一点。我已经创建了一个带有名字和姓氏的链接列表,但这只是我所能得到的。

任何帮助都会很棒: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 技术交流群。

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

发布评论

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

评论(3

彡翼 2024-10-28 02:15:09
  1. 创建一个具有两个链接字段(nextFirstName、nextLastName)和一个名称对象字段的链接类。
  2. 插入时,首先搜索位于该新对象 (LastName) 之前的 Link 对象,然后使用 nextLastName 字段将其插入到该对象之后。然后使用 nextFirstName 字段作为链接,对 FirstName 执行相同的操作。
  3. ????
  4. 利润!

这确实很像家庭作业:)

  1. Create a Link Class that has two link fields (nextFirstName, nextLastName) and a field for the Name Object.
  2. On insert, first search the Link object that comes before (LastName) this new one and insert it after that using the nextLastName field. Then do the same with the FirstName, using the nextFirstName field as the link.
  3. ?????
  4. profit!

This does smell a lot like homework :)

明月夜 2024-10-28 02:15:09

因为您已经实现了单链表,所以扩展到双向链表应该不会太困难。您已经有了后续的参考资料(见下图)。现在您还需要添加向后引用。另外,请注意下图中的蓝色线条。添加拼写属性的附加参考。因此每个节点都将具有变量:

private Node NextFirstName;
private Node PreviousFirstName;
private Node NextLastName;
private Node PreviousLastName;

在此处输入图像描述

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:

private Node NextFirstName;
private Node PreviousFirstName;
private Node NextLastName;
private Node PreviousLastName;

enter image description here

双马尾 2024-10-28 02:15:09

您不需要向后引用!该任务需要类似 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.

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