This is in java. I am confused on how to do this. I have to use the Deque
interface to print the deque backwards, i.e from back to front.
Here is the Deque interface :
public interface Deque<E> {
public int size();
public boolean isEmpty();
public E getFirst() throws EmptyDequeException;
public E getLast() throws EmptyDequeException;
public void addFirst (E element);
public void addLast (E element);
public E removeFirst() throws EmptyDequeException;
public E removeLast() throws EmptyDequeException;
}
Here is what I have :
static void _recursivePrint(Deque deque) throws EmptyDequeException{
if(deque.isEmpty())
return;
else {
print(deque.getLast() + " "); //use overloaded print
deque.removeLast();
_recursivePrint(deque); //recursive call it
}
}
Its all good, but for one problem. The problem is that I am required not
to change the original deque's structure. Anyone have any ideas they can throw
at me? I can't clone deque because its not provided in the interface of deque.