Question: 3.11: Array of Linked Lists Consider creating an array of linked lists to store structs Well call the array a table And well think of
3.11: Array of Linked Lists

Consider creating an array of linked lists to store structs Well call the array a "table" And well think of the structs as the data that needs to be stored, for example struct person { char *name int age; struct person * next; 1; The table will be of fixed size, for example: #define TABLE-SIZE 5 // This defines a constant in C struct linkedlist *table[TABLE_SIZE]; When a struct is to be stored in a linked-list, we already know how to do that from earlier exercises in this module . Thus, the only remaining question is: which of the linked lists (one per entry in the table) do we store a particular item? . To compute which entry, we'll use a calculation that retums an integer, as in /5 linked lists int computeCode (char *name, int age) int s -0 int i-0; while (name[i] ! II Add the letters, treating them as numbers. s + Cint) name [i]; return (s+age); // Combine with age Then, to decide which table entry, we'll use the above tableEntry-computeCode(name ,age) % TABLE-SIZE; Note: The computeCode () function (method) retums some integer. This integer cannot directly be used as the index into the table because it could be too large So, we compute the remainder when divided by the table size This will always produce a number between O and TABLE_SZE . Once we know which table entry (that is, which linked list), we can use our earier linked-list methods to insert into that list: addToList (table[tableEntry], name, age); Exercise 3.11: Implement the needed code in various methods in linkedlistTable.c to make this idea work. You have seen this data structure before. What is it called? Draw a memory diagram after the first three insertions. You can either use a markdown table, or draw on paper and add a photo to your README file Consider creating an array of linked lists to store structs Well call the array a "table" And well think of the structs as the data that needs to be stored, for example struct person { char *name int age; struct person * next; 1; The table will be of fixed size, for example: #define TABLE-SIZE 5 // This defines a constant in C struct linkedlist *table[TABLE_SIZE]; When a struct is to be stored in a linked-list, we already know how to do that from earlier exercises in this module . Thus, the only remaining question is: which of the linked lists (one per entry in the table) do we store a particular item? . To compute which entry, we'll use a calculation that retums an integer, as in /5 linked lists int computeCode (char *name, int age) int s -0 int i-0; while (name[i] ! II Add the letters, treating them as numbers. s + Cint) name [i]; return (s+age); // Combine with age Then, to decide which table entry, we'll use the above tableEntry-computeCode(name ,age) % TABLE-SIZE; Note: The computeCode () function (method) retums some integer. This integer cannot directly be used as the index into the table because it could be too large So, we compute the remainder when divided by the table size This will always produce a number between O and TABLE_SZE . Once we know which table entry (that is, which linked list), we can use our earier linked-list methods to insert into that list: addToList (table[tableEntry], name, age); Exercise 3.11: Implement the needed code in various methods in linkedlistTable.c to make this idea work. You have seen this data structure before. What is it called? Draw a memory diagram after the first three insertions. You can either use a markdown table, or draw on paper and add a photo to your README file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
