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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!