#include #include // DO NOT CHANGE THIS STRUCT struct node { struct node *next; int data; }; // MODIFY THIS FUNCTION // list_delete_min takes in the head of a linked list and deletes (and frees) // all instances of the minimum value in the list struct node *list_delete_min(struct node *head) { struct node *curr = head; struct node *prev = NULL; if (curr == NULL || curr->next == NULL) { free(curr); return NULL; } int minimum = 0; while (curr != NULL) { if (curr->data == minimum) { minimum = curr->data; } curr = curr->next; } curr = head; while (curr != NULL) { if (curr->data < minimum) { struct node *to_delete = curr; free(to_delete); } prev = curr; curr = curr->next; } return head; } //////////////////////////////////////////////////////////////////////// // DO NOT CHANGE THESE PROTOTYPES //////////////////////////////////////////////////////////////////////// struct node *args_to_list(int argc, char *argv[]); void print_list(struct node *head); void free_list(struct node *head); // DO NOT CHANGE THIS FUNCTION int main(int argc, char *argv[]) { struct node *head = args_to_list(argc, argv); printf("BEFORE: "); print_list(head); head = list_delete_min(head); printf("AFTER : "); print_list(head); free_list(head); return 0; } // DO NOT CHANGE THIS FUNCTION // Converts command-line args to a linked list of characters struct node *args_to_list(int argc, char *argv[]) { struct node *head = NULL; for (int i = argc - 1; i >= 1; i--) { struct node *new = malloc(sizeof(struct node)); new->data = atoi(argv[i]); new->next = head; head = new; } return head; } // DO NOT CHANGE THIS FUNCTION // Prints a linked list of integers void print_list(struct node *head) { struct node *curr = head; if (curr == NULL) { printf("NULL\n"); return; } while (curr != NULL) { printf("%d", curr->data); if (curr->next != NULL) { printf(" -> "); } curr = curr->next; } printf(" -> NULL\n"); } void free_list(struct node *head) { struct node *curr = head; while (curr != NULL) { struct node *to_free = curr; curr = curr->next; free(to_free); } }