Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
How do I create an application that uses a linked list. You must be able to do at least the following to the linked list:
check whether the list is empty
display the list
find the length of the list
destroy the list
retrieve the data in the nth node
search the list for a given item
insert an item in the list
delete an item from the list
Thanks ;)
Re: Linked Lists Java Programming HELPP P.S. I am a beginner in Java Programming
Quote:
Originally Posted by
judemartin99
How do I create an application that uses a linked list.
A (singly) linked list consists of nodes that usually look something like this,
Code:
class Node {
Data data;
Node next;
}
Each node holds some data. In the simplest case it could be an int. And each node is linked to the next node by holding a reference to it.
Then you need to come up with all the wanted operations on these linked nodes. Most involve you "walk" the chain of next references from the first up to the last node at the most (the one with a null next reference) and do something along the way. It could be you count the nodes to get the list length or you add a new node when you reach the end. Or you add it at the very beginning for that matter because it obviously is more efficient.