previous | start | next

Add to First Revised (cont.)

The complete code:

Node tmp = new Node(3);
tmp.next = start;
if ( start == null ) {
   last = tmp;
}
start = tmp;
   

It is easy to get this wrong by not updating last when the list was empty!

The complexity of this version is O(1)



previous | start | next