#include #include #include #include #include struct node { struct node *next; char data; }; // List 1: 'a' 'b' 'c' (3 nodes) // List 2: 'd' 'e' 'f' 'g' 'h' (5 nodes) // difference function should return 2 int len(struct node *head); int difference(struct node *head1, struct node *head2) { //TODO // count the number of nodes in each list int count1 = len(head1); int count2 = len(head2); // return abs(count1 - count2); if (count1 > count2) { return count1 - count2; } return count2 - count1; return 2; } int len(struct node *head) { struct node *tmp = head; int i = 0; while(tmp != NULL) { tmp = tmp->next; i++; } return i; } struct node *strings_to_list(int len, char *strings[]); // DO NOT CHANGE THIS MAIN FUNCTION int main(int argc, char *argv[]) { // create two linked lists from command line arguments int dash_arg = argc - 1; while (dash_arg > 0 && strcmp(argv[dash_arg], "-") != 0) { dash_arg = dash_arg - 1; } struct node *head1 = strings_to_list(dash_arg - 1, &argv[1]); struct node *head2 = strings_to_list(argc - dash_arg - 1, &argv[dash_arg + 1]); int diff = difference(head1, head2); printf("%d\n", diff); return 0; } // DO NOT CHANGE THIS FUNCTION // create linked list from array of strings struct node *strings_to_list(int len, char *strings[]) { struct node *head = NULL; for (int i = len - 1; i >= 0; i = i - 1) { struct node *n = malloc(sizeof (struct node)); assert(n != NULL); n->next = head; n->data = strings[i][0]; head = n; } return head; }