• Source
    1. /* Given a reference (pointer to pointer) to the head of a list
    2.   and an int, inserts a new node on the front of the list. */
    3. void push(struct Node** head_ref, int new_data)
    4. {
    5. /* 1. allocate node */
    6. struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
    7.  
    8. /* 2. put in the data */
    9. new_node->data = new_data;
    10.  
    11. /* 3. Make next of new node as head */
    12. new_node->next = (*head_ref);
    13.  
    14. /* 4. move the head to point to the new node */
    15. (*head_ref) = new_node;
    16. }