Question
class Node { public int data; public Node next; public Node(int data) { this.data = data; this.next = null; } } class LinkedList { private
class Node { public int data; public Node next;
public Node(int data) { this.data = data; this.next = null; } }
class LinkedList { private Node head; private Node tail; public LinkedList() { head = null; tail = null; } public void append(Node newNode) { /* Task 1: your solution goes here */ } public void printList() { Node node = head; while (node != null) { System.out.print(node.data + " "); node = node.next; } System.out.println(); } }
Question
Task 1. Please implement the function public void append(Node newNode) of class SinglyLinkedList. Add your solution after the comment "Task 1: your solution goes here"
-----------------------------------
class Main { public static void main(String[] args) { LinkedList numList = new LinkedList(); /* Task 2: your solution goes here */
numList.printList(); }
}
QUESTION
Task 2. Test the public void append(Node newNode) function you implemented. In the main() function,
create a list object and append three nodes, 1, 2, and 3, in sequence.
Use the function public void printList() of class SinglyLinkedList to print out the result list.
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