You are expected to complete this assignment individually. If you need help, you are invited to come to office hours and/or ask questions on piazza. Clarification questions about the assignments may be asked publicly. Once you have specific bugs related to your code, make the posts private.
This homework has several problems. We are also providing you with some resources on printf and error handling for this assignment.
You should submit four files for this assignment ( hw5.h, hw5.c, hw5_main.c, and Makefile) in your subversion repository as directed below.
You already created hw5.c and hw5.h in the warmup. Continue adding to those files for this homework.
You need to add the skeleton code so that your program will minimally execute. You must do this in case you do not complete your assignment. Our testing infrastructure needs to compile and execute even if you did not complete the entire assignment. Refer to past assignments on how to make skeleton code.
Write a function that returns the country with a sum of the highest score. It returns the Country. If two of them tie, then you may return either one.
enum Country max_country(llist *list);
There are various sorting algorithms that work with arrays. With linked lists, they are much more complex. Instead of sorting an existing array, the best way is to insert items in sorted order. That is, we make sure that at all times, the array is sorted, allowing us to easily maintain sorted order by carefully inserting new items.
Note: I am not asking you to sort an existing, unsorted linked list. We will also not test your function by calling it with an unsorted list.
You are going to write three different functions that insert gymnasts in sorted order in different ways - by last name (head points to earliest in alphabetical order. If two have the same last name, then they are ordered by first name), by country (countries are sorted by the value of the enumerated type of their country, gymnasts may be in any order within a country. Country 0 would be at the head of the list), and by an individual gymnast's total score (head points to gymnast with highest score). If two gymnasts have the same value (e.g. country or total), the new gymnast is placed after the last gymnast with the identical value.
llist *add_sorted_name(gymnast_info *ginfo, llist *head); llist *add_sorted_country(gymnast_info *ginfo, llist *head); llist *add_sorted_total(gymnast_info *ginfo, llist *head);
What you wrote before is great once a competition has ended and all the scores are known. However, during the course of a competition, new scores are being added, and the order of the gymnasts need to change to reflect that.
In this problem, you are going to write a function that takes in a list that is already sorted in a particular way with one exception - the gymnast whose single score on a single update has just been updated from 0 to a value between 0 and 10. Based on the information that only that gymnast's score has changed, you need to modify the list to be in sorted order.
You first need to implement a function that will modify a single score of a single gymnast:
This function returns a pointer to the ginfo struct it modified. If it did not find the gymnast, it returns NULL.gymnast_info *modify_score(char *first, char *last, enum Event e, float score, llist *head);
You then need to implement two functions that will reorder the linked lists based on two rankings.
llist *modify_sorted_total(gymnast_info *ginfo, llist *head);
For modify_sorted_total, each individual gymnast begins almost sorted by the sum of their four scores. No more than one gymnast is out of order. This function is given two pointers - the head of the list and the node whose information has changed (the score has increased). Given this information, it makes any modifications necessary so that when it returns, the list is now in completely sorted order. It returns a pointer to the new head of the list (the head may or may not have changed).
The gymnasts were originally added using the add_sorted_country with a score of 0. Each time a gymnast receives a score, the gymnast's score is changed, and this is called to resort (if necessary). The countries change position relative to each other based on which country has the highest sum of the scores of their gymnasts. The country with the highest score needs to be at the head. The order of the gymnasts within a country must stay the same - only the order of the countries may change. This will only be called when a single gymnast has been modified, so only one country needs to change position. This function needs to modify the order (if necessary) to maintain the sorting property. It returns the head to the resulting list (which may or may not have changed).llist *modify_sorted_country(gymnast_info *ginfo, llist *head);
$ svn add hw5.h hw5.c hw5_main.c
$ svn commit -m "hw5 complete"