#include "list_handling.h" #include #include #include void print_list(struct event *head) { while (head != NULL) { printf("%s\n", head->date); printf("%s\n", head->summary); head = head->next; } } void sorted_insert(struct event** head, char date[], char summary[]) { struct event *new_node = malloc(sizeof(struct event)); strcpy((*new_node).date, date); strcpy((*new_node).summary, summary); if (*head == NULL || strcmp((*head)->date, new_node->date) >= 0) { new_node->next = *head; *head = new_node; } else { // Locate the node before the point of insertion struct event* current = *head; while (current->next!=NULL && strcmp(current->next->date, new_node->date) < 0) { current = current->next; } new_node->next = current->next; current->next = new_node; } } void free_list(struct event *head) { struct event* tmp; while (head != NULL) { tmp = head; head = head->next; free(tmp); } } void print_upcoming(struct event *head, char current_date[]) { while (head != NULL) { if (strcmp(head->date, current_date) >= 0) { printf("%s\n", head->date); printf("%s\n", head->summary); } head = head->next; } }