Linked List | Set 2 ( Inserting a node ) | Inserts a new node after the given prev_node . ; 1. Check if the given Node is null ; 2 & 3 : Allocate the Node & Put in the data ; 4. Make next of new Node as next of prev_node ; 5. make next of prev_node as new_node
public void insertAfter ( Node prev_node , int new_data ) { if ( prev_node == null ) { Console . WriteLine ( " The ▁ given ▁ previous ▁ node " + " ▁ cannot ▁ be ▁ null " ) ; return ; } Node new_node = new Node ( new_data ) ; new_node . next = prev_node . next ; prev_node . next = new_node ; }