Linked List | Set 2 ( Inserting a node ) | This function is in LinkedList class . Inserts a new node after the given prev_node . This method is defined inside LinkedList class shown above ; 1. check if the given prev_node exists ; 2. Create new node & 3. Put in the data ; 4. Make next of new Node as next of prev_node ; 5. make next of prev_node as new_node
def insertAfter ( self , prev_node , new_data ) : NEW_LINE INDENT if prev_node is None : NEW_LINE INDENT print " The ▁ given ▁ previous ▁ node ▁ must ▁ inLinkedList . " NEW_LINE return NEW_LINE DEDENT new_node = Node ( new_data ) NEW_LINE new_node . next = prev_node . next NEW_LINE prev_node . next = new_node NEW_LINE DEDENT