Linked List | Set 2 ( Inserting a node ) | This function is in LinkedList class . Inserts a new Node at front of the list . This method is defined inside LinkedList class shown above ; 1 & 2 : Allocate the Node & Put in the data ; 3. Make next of new Node as head ; 4. Move the head to point to new Node
public void push ( int new_data ) { Node new_node = new Node ( new_data ) ; new_node . next = head ; head = new_node ; }