Linked List Test Part 2

By Mickey Arnold
Last updated 10 months ago
3 Questions
Part 1 : Show the output of each block of code below. ( 50 points ) If a syntax or run-time error would occur, write error.

1. What is the output of code below?

ListNode x = new ListNode("8",new ListNode("2",new ListNode("6",null)));

out.println(x.getValue());
out.println(x.getNext().getNext().getValue());
out.println(x.getNext().getValue());
out.println(x.getNext().getNext().getNext());

2.What is the output of code below?

ListNode z = new ListNode("slide",new ListNode("speed", new ListNode("slow",new ListNode("dance", new ListNode("skip",null)))));


while(z!=null)
{
out.println(z.getValue());
z=z.getNext();
}

1. What is the output of code below?

ListNode x = new ListNode("8",new ListNode("2",new ListNode("6",null)));

out.println(x.getValue());
out.println(x.getNext().getNext().getValue());
out.println(x.getNext().getValue());
out.println(x.getNext().getNext().getNext());


What is the output of code below?
ListNode z = new ListNode("slide",new ListNode("speed", new ListNode("slow",new ListNode("dance", new ListNode("skip",null)))));

while(z!=null)
{
out.println(z.getValue());
z=z.getNext();
}


Part 2 : Complete method countEm(). ( 50 points )

//method countEm will return the count of all nums>b and <c

public int countEm(ListNode list, Comparable b, Comparable c)
{

///Code here///

}