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
34
#include <stdio.h>
#include <stdlib.h>

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

// WRONG!!!!
struct Node* append_to_list(struct Node* head, int value) {  // WRONG!!!
    struct Node* tail = head;
    while(tail != NULL) {
        tail = tail -> next;
    }
    assert(tail == NULL);
    tail = malloc(sizeof(*new_node));
    new_node -> value = value;
    new_node -> next  = NULL;
    head -> next = tail; // What if the list has >= nodes????
    return new_node;
}

void print_linked_list_of_ints(struct Node* head) {
    for(struct Node* curr = head; curr != NULL; curr = curr -> next) {
        printf("curr -> value == %d\n", curr -> value);
    }
}

int main(int argc, char* argv[]) {

    // TODO:  Free memory before we exit.
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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