Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 [ 7 0 points ] In this question, you are going to modify the functionality of phonebook.c . Recall that a link list
Question points
In this question, you are going to modify the functionality of phonebook.c Recall that a
link list is a datastructure that contains a pointer to the next object. In A we used an
array, but that has some disadvantages. We are going to modify phonebook.c to use a list
structure. We will still use an array to allocate all the items we need, so will need a method
to keep track of which items are used, and which are not this is usually called a freelist as
well as a method to know what item in the array the list starts at usually called the head of
the list Its a good practice to put all of the components together into a structure that can
be passed to functions needing to work on the list we will call this struct phonebook list
a points Create a structure that contains all the components needed to manage the
list. Modify the structure of the phonebook entries to include pointer to the next item
in the list. Write a function phonebook init initialize the array of structures, and any
supporting structures you need. This function should take argument, a pointer to
struct phonebook list.
b points Modify phonebook add from A to use the list structure. This function
should find a node on the freelist and add it to the end off the list. It should take
arguments:
a pointer to struct phonebook list
the struct to add
As before, the function should return an int: if the item is added successfully, and
if the item is not. Note that unlike in A the size is no longer a required parameter.
c points Modify phonebook find from A to work with the list structure. It will
take arguments.
a pointer to struct phonebook list
a key a name to find
This function should return a pointer to the first entry that matches the name starting
at the head If no match is found, then the function should return NULL.
d points Modify phonebook remove from A to work with the list structure. It
should take arguments:
a pointer to struct phonebook list
a key a name to remove
If the key is found it should be removed from the list and the list relinked and the
node should be added to the freelist. The function should return am int: if the
item was found and removed. if the item could not be found.
e points Modify phonebook print from A to work with the list structure. it should
take argument.
a pointer to struct phonebook list
The function then prints all the phonebook entries, each on a separate line. The output
should be similar to the following:
"Jon"
"Kyle"
f points Modify main from A to work with the list structure. You will need to call
phonebook init, and modify calles to phonebook add, phonebook find, phonebook remove,
and phonebook print. All other functionality should be the same as Aand infact
its operation should be identical
a for add; eg
a
Jon
This should add a phonebook entry with the given name and phone number.
f for find; eg
f
Jon
In this example, the output should be the value corresponding to Jon if the key
exists in the phonebook, or Key not found if the key is not in the phonebook.
r for remove; eg
r
Jon
The output should be success or fail depending on whether the key was found
and removed.
p for print all; eg
p
The output should be all phonebook entries.
q to quit the program.
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