#include #include #include struct node_struct { char val[80]; struct node_struct *next; }; typedef struct node_struct Node; void print(Node *head); void add(Node **headptr, char newval[]); void delete(Node **headptr); int main() { Node *head = NULL; print(head); add(&head, "University"); add(&head, "State"); add(&head, "Colorado"); print(head); delete(&head); print(head); // Should really free memory here return 0; } void print(Node *n) { printf("Nodes in the list:"); for (; n != NULL; n=n->next) printf(" %s", n->val); printf("\n"); } void add(Node **headptr, char val[]) { Node *new = malloc(sizeof(Node)); if (new == NULL) { fprintf(stderr, "Can't allocate a Node\n"); return; } strcpy(new->val, val); new->next = *headptr; *headptr = new; } void delete(Node **headptr) { Node *victim = *headptr; if (victim == NULL) return; *headptr = victim->next; free(victim); }