Linked List Test Part 2
star
star
star
star
star
Last updated over 1 year 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();
}
25
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());
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());
25
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();}
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();
}
50
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///
}
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///
}