Answered step by step
Verified Expert Solution
Question
1 Approved Answer
An array of linked lists Consider creating an array of linked lists to store structs: We'll call the array a table . And we'll think
An array of linked lists Consider creating an array of linked lists to store structs: We'll call the array a "table" . And we'll think of the structs as the data that needs to be stored, for example: struct person t char name; int age; struct person * next; The table will be of fixed size, for example: #define TABLE-SIZE 5 // This defines a constant in C struct linkedlist *table[TABLE_SIZE]; //5 linked lists 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, well use a calculation that retums an integer, as in: int computeCode Cchar *name, int age) int s -0 int i0; while Cname[i] !-// Add the letters, treating them as numbers s += (int) name[i]; return (s+age); /Combine with age An array of linked lists Consider creating an array of linked lists to store structs: We'll call the array a "table" . And we'll think of the structs as the data that needs to be stored, for example: struct person t char name; int age; struct person * next; The table will be of fixed size, for example: #define TABLE-SIZE 5 // This defines a constant in C struct linkedlist *table[TABLE_SIZE]; //5 linked lists 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, well use a calculation that retums an integer, as in: int computeCode Cchar *name, int age) int s -0 int i0; while Cname[i] !-// Add the letters, treating them as numbers s += (int) name[i]; return (s+age); /Combine with age
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started