Question: 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

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!