Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions