1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>

void insert_node(Node** a_head, int value) {
    // BAD assert(..)
    assert(a_head != NULL);  // because depends on external code following rules

    Node* new_node = malloc(sizeof(*new_node));
    new_node -> value = value;
    new_node -> next  = NULL;
    *a_head = new_node;

    assert(*a_head != NULL);  // just added node so can't be empty
    assert((*a_head) -> value == value);
    assert(new_node != NULL); //
}

This content is protected and may not be shared, uploaded, or distributed.    © 2019 Alexander J. Quinn.