With the following structures allocated:

typedef struct {
char *name;
int commonality;
int weight;
}

typedef struct {
char *name;
char *description;
double area;
int monsters;
monster *monsters;
} region;

typedef struct {
char *name;
double diameter;
int nregions;
regions *regions;
} planet;
  • Write functions to free all memory allocated for a planet, its child regions, and their child monsters.
  • The functions should call each other as appropriate - use functions to free enclosed structures.
  • Don't free any memory that wouldn't have been allocated.
  • Don't free anything more than once. Don't worry about headers.
  • Your function prototypes should be:
void dispose_monster(monster *monster);
void dispose_region(region *region);
void dispose_planet(planet *planet);

With the following structures defined:

struct monster_struct {
char *name;
int commonality;
int weight;
struct monster_struct *next;
};

typedef struct monster_struct monster;

typedef struct monster_list {
monster *head;
}
  • Write functions to return the second-most-common monster and the third-lightest monster in the list.
  • Don't worry about headers.
  • Don't worry about which way to resolve ties.
  • The list will always have three monsters in it.
  • Your function prototype should be:
monster *second_most_common(monster_list *m1);
monster *third_lightest(monster_list *ml);

Analysis:

  • In big-O terms what is the performance of each function? Why?
  • Would either adding a tail pointer to the list, or making it a doubly-linked list, increase performance? Why or why not?
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.