// Week 7 Thursday Lecture // Create a list with 3 nodes // Print the the contents of the first 3 nodes // Write code to free our nodes // This is repetitive // We need to have functions to create nodes // We need a less manual way to print the list // We need a way to free nodes #include #include struct node { int data; struct node *next; }; int main(void) { struct node *head = NULL; struct node *new_node = malloc(sizeof(struct node)); new_node->data = 3; new_node->next = NULL; head = new_node; new_node = malloc(sizeof(struct node)); new_node->data = 9; new_node->next = head; head = new_node; new_node = malloc(sizeof(struct node)); new_node->data = 7; new_node->next = head; head = new_node; // Print first 3 nodes in list printf("%d ", head->data); printf("%d ", head->next->data); printf("%d ", head->next->next->data); return 0; }