具有两个数据字段的java链接列表
有人可以帮助我开始,我不知道如何创建一个可以包含两个数据字段的链接列表
为链接列表类编写Java程序。形成链表的节点应包含两个数据字段:1.ID(唯一)2.年龄。链表中的所有节点都按照年龄递增排序。 在链表上实现以下操作。
(一个) 遍历链表并打印所有节点的ID、Age。
(二) 将新节点插入列表,同时保持列表排序。
(三) 从给定 ID 的列表中删除节点。
(四) 在链接列表上查询。基本上,有两种类型的查询。一是输入唯一ID,并显示对应的年龄。另一种是输入年龄,然后显示所有该年龄的ID。
(五) 将此链接列表更改为按年龄递减排序的排序列表。 您还应该在程序中至少有3个节点的示例上尝试上述操作,并提供执行结果的屏幕截图
Can someone help me get started, i'm not sure how to create a linklist that can contain two data field
Write the Java program for a linked list class. The node that forms the linked list should contain two data fields: 1. ID (unique) 2. Age. All the nodes in the linked list are sorted increasingly by the age.
Implement the following operations on the linked list.
(a)
Traverse the linked list and print the ID, Age for all the nodes.
(b)
Insert a new node to the list while keeping the list sorted.
(c)
Delete a node from the list for a given ID.
(d)
Query on the link list. Basically, there are two types of queries. One is to input the unique ID, and display the corresponding age. And the other is to input the age, then display all the IDs with that age.
(e)
Change this link list to a sorted list that is ordered by the age decreasingly.
You should also try above operations on an example with at least 3 nodes in your program and provide the screenshot for the execution results
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您基本上必须使用类型扩展 LinkedList 类,因为您的自定义对象可能类似于
Person
。在类中实现查询、删除等方法。
You basically have to extend the LinkedList class with type as your custom object may be like a
Person
.implement your methods inside the class for query, delete etc.
您应该提供当前的实施尝试。
但是,如果您不理解 LinkedList 的概念,这里是一个抽象:
这应该有足够的信息来帮助您入门,尝试实现它,如果您遇到任何问题,请向我们展示代码,我们会做我们尽力帮助您。
You should provide your current implementation attempt.
However if you don't understand the concept of a LinkedList here is an abstract :
That should be enough info to get you started , try implementing it and if you run into any problems show us the code and we will do our best to help you.