This keeps rest part of list intact .
if ( count == n ) { var d = c . next ; c . next = link ; end . next = d ; var head = A ; while ( head != null ) { document . write ( head . data + " " ) ; head = head . next ; } return ; } c = c . next ; } }