Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 2 review Spring2007: Write insertAfter

Back to Midterm Exam 2 Review-Spring 2007

Questions? Answers? Comments?


public void insertAfterNext(LLNode twoBefore, LLnode newOne){
if (twoBefore.getNext() == null) {
twoBefore.insertAfter(newOne);
}    
else {
LLNode oneBefore = twoBefore.getNext();
LLNode oneAfter = oneBefore.getNext();    
oneBefore.setNext(newOne);
    newOne.setNext(oneAfter);
  }
}

public void insertAfterNext(LLNode node){
    if (this.getNext() != null){
        this.getNext().insertAfter(node);
    }
    else{
        this.insertAfter(node);
    }
}

Link to this Page