Notifications



Goals for this homework

  • Gain experience with structs and enumerated types
  • Gain experience with linked lists

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.

Set Up

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.

Problem 1: create_gymnast

Write a function that returns the country with a sum of the highest score. It returns the Country.

enum Country max_country(llist *list);

Problem 3: insertion sorting

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), by country (countries are sorted by the value of the enumerated type of their country, gymnasts may be in any order within a country), and by an individual gymnast's total score (head points to gymnast with highest score).

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);

Don't forget to complete this portion, test it, and commit it before moving on! You need this to work in order to implement the next part!
You also want this working for when we get to function pointers. Later in the course, we'll be able to use a single function for all three!

Problem 3: dynamic sorting

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:

gymnast_info *modify_score(char *first, char *last, enum Event e, float score, llist *head);
This function returns a pointer to the ginfo struct it modified. If it did not find the gymnast, it returns NULL.

You then need to implement two functions that will reorder the linked lists based on two rankings.

For modify_sorted_total, each individual gymnast is sorted by the sum of their four scores. This passes in a pointer to the gymnast that was changed as well as the head of the linked list. Given this information, it makes any modifications necessary so that the list is left in order. It returns a pointer to the new head of the list (the head may or may not have changed).

llist *modify_sorted_total(gymnast_info *ginfo, llist *head);

The sets of gymnasts from a particular country are all together. At the beginning, all scores are 0. As scores get inserted, the countries change position relative to each other based on which country has the highest sum of the scores of their gymnasts. In this function, the list that it receives has all gymnasts of a certain country together, and the countries themselves are ordered by the top score being at the head. This needs to modify it (if necessary) to maintain that order.

llist *modify_sorted_country(gymnast_info *ginfo, llist *head);
It returns the head to the resulting list (which may or may not have changed).

Submit

At this point, you should have done the following:
  • Created four files and filled in the proper information: hw5.h, hw5.c, hw5_main.c, and Makefile inside your hw5 directory.
  • $ svn add hw5.h hw5.c hw5_main.c
    
  • Implemented all of your functions. If not, you at least need skeletons of your functions so that our automated tests will compile for the functions you did write.
  • Compiled your executable manually and with the Makefile
  • Implemented your test cases
  • Executed your code
  • Debugged your code
  • $ svn commit -m "hw5 complete"