开发者

java linklist with two data field

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开发者_如何学Python 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


You basically have to extend the LinkedList class with type as your custom object may be like a Person.

public class PersonList extends LinkedList<Person> {

}

implement your methods inside the class for query, delete etc.


You should provide your current implementation attempt.
However if you don't understand the concept of a LinkedList here is an abstract :

A LinkedList is like the name implies a list of Links so in order to explain the Linked list let us first go over the concept of a link :
A link should have the following abilities :
1)know the next link(reference to next link)
2)contain data field(or fields in your case) that can be retrieved and set externally

Now implementing a LinkedList after knowing the concept of a Link is very simple
Consider the following as a LinkedList

Link1->Link2->Link3->Link4..

Now since every Link knows (has a reference to the next Link) the next Link All the LinkedList needs to know is where to start(First Link ?)
You should have noticed by now that LinkedList has no size limit Dynamic Data Structure

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜