1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>

typedef struct _Node {
    int value;
    struct _Node* next;
} Node;

void append(Node** a_head, int value) {
    Node* tail = *a_head;
    while(tail != NULL && tail -> next != NULL) {
        tail = tail -> next;
    }

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

    assert(tail != NULL);  // Lets us know that we forgot to handle the case
                           // of an empty list.
    tail -> next = new_node;

    // FIXME:  In its current state, this function will cause a segmentation
    //         fault when the list is empty.  Also, this isn't 100% finished.
}


int main(int argc, char* argv[]) {
    Node* head = NULL;
    insert(&head, 3);
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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