Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Consider the LinkedList class with an inner Node class as following: public class LinkedList { private Node head; private class Node{ private T data;

3. Consider the LinkedList class with an inner Node class as following:

public class LinkedList{

private Node head;

private class Node{

private T data;

private Node next;

public Node(T d) {

data = d;

next = null;

}

}

}

A linked list of integers created from the above List class is represented by the following diagram:

image text in transcribed

a. What is curNode.data after the following code segment is executed? (5 points)

Node curNode = head;

curNode = curNode.next.next;

b. What will be displayed after the following code segment is executed? (5 points)

Node curNode = head;

int n = 0;

while(curNode!= null){

n + = curNode.data;

curNode = curNode.next;

}

System.out.println(n= + n);

c. Draw a diagram of the above list after the following lines of code have been executed (5 points)

Node newNode = new Node(6);

Node curNode = head.next; newNode.next = curNode.next;

curNode.next = newNode;

d. In addition to the code above, assume the following code executes. Draw a diagram of the list after this code executes. (5 points)

Node curNode = head; curNode = curNode.next;

curNode = curNode.next;

Node nextNode= curNode.next;

curNode.next = nextNode.next;

nextNode = null;

7 3 4 8 head

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions