hi, i am trying out past year questions for a resit and am stuck with the question below.
Question 1
In the following you may assume the existence of the ListIterator<e> interface and LinkedList<E> class with the following methods
public interface ListIterator<E>
{
E next();
boolean hasNext();
}
public class LinkedList<E>
{
public void addLast(E obj){..}
public int size(){..}
public ListIterator<E> listIterator(){...}
}
Finished the design of the printBackward method given below using the methods listed above in the ListIterator<E> interface and LinkedList<E> class. You should not introduce any new variable tinto the method. In your answer, do not copy the whole method. Write contents of the Initialisation 1, Initialisation 2, Block 1, Block 2, Block 3 . The printBackward method should be written recursive in a singly list backward. The parameter n specifies the size of the list.
public class MyLinkedList<E> extends LinkedList<E>
{
public void printBackward(int n)
{
if(n > 0){
ListIterator<E> itr = /**Initialisation 1**/ list1.listIterator();
int count = /**Initialisation 2**/ 0;
E item;
while(itr.hasNext())
{
/**Block 1**/ addLast(list1); printBackward(); count --;
}
/**Block 2**/ E.next;
}else
/**Block 3**/ return;
}
}
}
I have inserted my answers next to the /** ..**/ but am unsure if they are correct. It would be much appreciated if someone could help me correct my mistakes