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:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started