Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3) (8 pts) The following method is a failed attempt to print out the element contents of each Node in the DoublyLinkedList ; assume that

3)

(8 pts) The following method is a failed attempt to print out the element contents of each Node in the DoublyLinkedList; assume that headNode is a reference to the front of the list (head). State two reasons why it is written incorrectly. Each reason is for a different test case not handled. Then provide the fix.

void printNodes (Node headNode)

{

while (headNode.getNextNode() != null)

{

System.out.println (Node Info: + headNode.getElement());

headNode = headNode.getNextNode();

}

}

4)

Using the following method, where headNode is a reference to the front of the DoublyLinkedList (head) that contains the following Node elements:

head <--> A<--> B<--> C<--> D

What should the modified linked list look like after the method2 call.

void method2 (Node headNode)

{

Node temp = null;

Node current = headNode;

while (current != null)

{

temp = current.getPrevNode();

current.setPrevNode (current.getNextNode());

current.setNextNode (temp);

current = current.getPrevNode();

}

if (temp != null)

headNode = temp.getPrevNode();

}

5)

Show what is written by the following segment of code:

queue = new MyQueue();

String item0 = ;

String item1 = B;

String item2 = item1 + E;

String item3 = P;

enqueue (item2);

enqueue (item2 + E);

enqueue (item1);

dequeue();

item1 = item2 + E;

enqueue (item1);

enqueue (item3);

while (!queue.isEmpty())

item0 = queue.dequeue();

print (Item: + item0);

print (Item0: + item0);

print (Item1: + item1);

print (Item2: + item2);

System.out.print (Item3: + item3);

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_2

Step: 3

blur-text-image_3

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago