Question
JAVA Lab: Implement a Linked List For this task, you will have to implement a Linked List, which is a node-based data structure. This will
JAVA Lab: Implement a Linked List
For this task, you will have to implement a Linked List, which is a node-based data structure. This will be easier than it seems. Recall that a node-based data structure is simply a collection of "node" objects. Each node object contains a reference to one or more other nodes, and a bit of data. Thus, your node might look like this:
public class Node { Node next; Integer data; }
Of course, if you wanted to use generics, you could create a generic Node class which used the generic type for the "data" variable too.
A LinkedList Class might then look like this:
public class LinkedList { Node head; // utility methods }
A node for a Linked List might be improved by having an "add()" method with special behavior: when invoked, the "add()" method will traverse the linked list to add a given node to the end of the list.
algorithm add is: input: Node newNode -> The new node to add let "currentNode" = head; while current.next != null current = current.next current.next = newNode
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started