public void deleteLast(){
//check if this is the last node
if(this.next == null) {
this = null;
return;
}
//look 2 nodes ahead to see if we have reached the end
Node temp = this;
while(temp.next.next != null){
temp = temp.next;
}
//Finally, move to last node and set it null
temp = temp.next;
temp = null;
}
No comments:
Post a Comment