Question: 5. Given the following definition of class Node: class Node { public int item; public Node next; public Node ( int i, Node n )
5. Given the following definition of class Node: class Node { public int item; public Node next; public Node ( int i, Node n ) { item = i; next = n; }; } and the following declarations: Node list, p, q; Assume the structure starts as below. Draw the structure created by executing the following statements. Each part is independent. list 1 2 3 4 5 [2] a) p = list; q = null; while ( p != null && p.item < 5 ) { p.item = p.item + 1; q = p.next; p = q.next; }; [2] b) p = list; while ( p != null ) { del(p); p = p.next; }; : private void del ( Node n ) { n = null; }; [6] c) Assume the declaration of the class Node as above. Write a method concat that concatenates (joins) list2 to the end of list1. That is, in the result the first node of list2 should follow the last node of list1.The method returns resulting list. No new nodes should be created. If list1 is empty the function should return list2 as the result. private Node concat ( Node list1, Node list2 ) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
