All pastes #190891 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-10-04 12:34 UTC
rendered paste body
  // Reverse the order of the list
    public void reverse()
    {
        Node n=first;
        first=null;
        last=null;
        for(;n!=null;n=n.getNext()) { 
            addStart(n.getValue());
            } 
            
      
        
        // left as an exercise
    }
    
    public void reverseRec() { 
        //Node lst = first;
        

        //Node f = first;
        reverseRecursive(first);
      //  last = f;
       // last.setNext(null);
        //lst.setNext(null);
        
    }
    private Node reverseRecursive(Node thisNode) { 
        Node nextNode = thisNode.getNext();
        if(thisNode != null) { 
            
            (thisNode.getNext()).setNext( reverseRecursive(nextNode) );
        }
        return thisNode;
            
       
        
    }