This method is supposed to reverse a stack by making a new stack and pushing popped items from this stack to the revertStack and then returning the reverted stack. When I run some tests, it returns an empty stack in stead. Any clues?
public LinkedStack<E> reversed()
{
LinkedStack<E> revertStack = new LinkedStack<E>();
if(this.isEmpty()==true){
return this;
}
else{
while(this.isEmpty()==false)
{
Node<E> snode=this.top;
revertStack.push(snode.getData());
this.pop();
snode=snode.getLink();
}
return revertStack;
}
}