java - Reversed method does nothing to stack -
this method supposed return copy of current stack items reversed.
public linkedstack<e> reversed() { linkedstack<e> that= new linkedstack<e>(); if(this.isempty()==true){ return this; } else{ while(this.isempty())//changed this.isempty()==true { node<e> snode=this.top; that.push(snode.getdata()); this.pop(); snode=snode.getlink(); /* that.push(pop()); works */ } return that; } }
update ok 1 of answers seems bring me closer solution. works stack created in method. problem i'm having linking stack can return copy of this
stack. i'm using linked stack.
why not
while(!isempty()) { revertstack.push(pop()); }
at same time @ original loop particularly first line see may causing problems
Comments
Post a Comment