Answered step by step
Verified Expert Solution
Link Copied!

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 2[70 points]
In this question, you are going to modify the functionality of phonebook.c. Recall that a
link list is a data-structure that contains a pointer to the next object. In A4 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 free-list), 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)(20 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 1 argument, a pointer to
struct phonebook list.
(b)(10 points) Modify phonebook add from A4 to use the list structure. This function
should find a node on the free-list and add it to the end off the list. It should take 2
arguments:
(1) a pointer to struct phonebook list
(2) the struct to add
As before, the function should return an int: 0 if the item is added successfully, and
-1 if the item is not. Note that unlike in A4, the size is no longer a required parameter.
(c)(10 points) Modify phonebook find from A4 to work with the list structure. It will
take 2 arguments.
2
(1) a pointer to struct phonebook list
(2) 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)(10 points) Modify phonebook remove from A4 to work with the list structure. It
should take 2 arguments:
(1) a pointer to struct phonebook list
(2) 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 free-list. The function should return am int: 0 if the
item was found and removed. -1 if the item could not be found.
(e)(10 points) Modify phonebook print from A4 to work with the list structure. it should
take 1 argument.
(1) 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" ->11234567890
"Kyle" ->13220000001
(f)(10 points) Modify main from A4 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 A4(and in-fact
its operation should be identical).
a for add; e.g.,
a
Jon
11234567890
This should add a phonebook entry with the given name and phone number.
f for find; e.g.,
f
Jon
3
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; e.g.,
r
Jon
The output should be success or fail, depending on whether the key was found
and removed.
p for print all; e.g.,
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

How do river bends, or meanders, move or migrate?

Answered: 1 week ago

Question

What problem(s) does this public have related to this issue?

Answered: 1 week ago

Question

Who is your key public?

Answered: 1 week ago