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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include "linked_list.h"
void _print_integer(void* a_value) {
int* a_num = a_value;
printf("%d", *a_num);
}
int main(int argc, char* argv[]) {
int numbers[4] = {5, 2, 9, 8473};
// linked list of size 0
// NULL
Node* head = NULL;
Node* tail = NULL;
print_linked_list(head, _print_integer);
assert(head == NULL);
assert(tail == NULL);
// linked list of size 1
// [5]->NULL
append(numbers + 0, &head, &tail);
print_linked_list(head, _print_integer);
assert(head != NULL);
assert(tail != NULL);
assert(head == tail);
int* tail_value = tail->a_value;
assert(*tail_value == 5);
// linked list of size 2
// [5]->[2]->NULL
append(numbers + 1, &head, &tail);
print_linked_list(head, _print_integer);
assert(head != tail);
tail_value = tail->a_value;
assert(*tail_value == 2);
// linked list of size 3
// [5]->[2]->[9]->NULL
append(numbers + 2, &head, &tail);
print_linked_list(head, _print_integer);
tail_value = tail->a_value;
assert(*tail_value == 9);
// linked list of size 4
// [5]->[2]->[9]->[8473]->NULL
append(numbers + 3, &head, &tail);
print_linked_list(head, _print_integer);
tail_value = tail->a_value;
assert(*tail_value == 8473);
// a later node in a linked list is a valid linked list
print_linked_list(head->next, _print_integer);
destroy_linked_list(&head, &tail);
assert(head == NULL);
assert(tail == NULL);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.