text: Linked List | Set 2 ( Inserting a node ) | Given a node prev_node , insert a new node after the given prev_node ; 1. check if the given prev_node is NULL ; 2. Allocate the Node & 3. Put in the data ; 4. Make next of new node as next of prev_node ; 5. move the next of prev_node as new_node
code: void insertAfter ( struct Node * prev_node , int new_data ) { if ( prev_node == NULL ) { printf ( " the ▁ given ▁ previous ▁ node ▁ cannot ▁ be ▁ NULL " ) ; return ; } struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = prev_node -> next ; prev_node -> next = new_node ; }