fauxMidterm - Question 1: You must be kidding! (groan) (15...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Question 1 : You must be kidding! (groan) (15 pts, 40 min) We have a simple linked list that consists of kids’ names (a standard C string) and the grade they are in – an integer between 0 (Kindergarten) and 12. The structure appears as follows, with an example: typdef struct kid_node { int grade; char *name; struct kid_node *next; } kid_t; For “administrative reasons”, we’d like to categorize our kids by grade. We copy the kids’ information into an array of linked lists indexed by the grade. Note that changing ANY of the data In these structures here should NOT Affect the original list above. Fill in the blanks in the below code: a) The create_kid_array function will return a pointer to the new array. Remember, the range of grades is 0-12, inclusive, and the original list MUST remain unchanged. #define MAXGRADE 12 kid_t **create_kid_array (kid_t *kid) { int i; /* in case you need an int */ kid_t *temp; /* or kid_t ptr somewhere */ kid_t **kid_array = (kid_t **) malloc (_______________________); if (kid_array == NULL) return NULL; /* malloc has no space! */ /* Additional initializing – add some code below */ ret } 3 1 3 kid Kim Paula Juan Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 kid_array 1 Paula 3 3 Kim Juan
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 kid_array 1 Paula 3 3 Kim Juan Question 1 : You must be kidding! (groan) …continued… (15 pts, 40min) Typedef struct kid_node { int grade; char *name; struct kid_node *next; } kid_t; b) For every Yin, there is a Yang. Now that we have a function for creating kid arrays, we must create a function that
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

fauxMidterm - Question 1: You must be kidding! (groan) (15...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online