/** * Integer linked list example * CSE 374 */ #include #include #include "linkedlist.h" IntListNode* makeNode(int data, IntListNode* next) { IntListNode* n = (IntListNode*) malloc(sizeof(IntListNode)); n->data = data; n->next = next; return n; } IntListNode* fromArray(int* array, int length) { IntListNode* front = NULL; for (int i = length - 1; i >= 0; i--) { front = makeNode(array[i], front); } return front; } void freeList(IntListNode* list) { while (list != NULL) { IntListNode* next = list->next; free(list); list = next; } } void printList(IntListNode* list) { printf("["); while (list != NULL) { printf(" %d", list->data); list = list->next; } printf(" ]\n"); }