Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Makefile that builds the program list from a C file list.c . Your Makefile should use the compiler flags discussed in class, and
Write a Makefile that builds the program list from a C file list.c Your Makefile should
use the compiler flags discussed in class, and have the all and clean targets as shown
previously. You should also include the flag Wextra as discussed in the lab.
Extending the List
Insert
As mentioned in LE there are different types of insertion to a list. We will now add the
more complicated insert before and insert after.
Insert Before Adds a node to the list immediately prior to a given node current node
There are four steps for this operation:
Get the node pointed to by the free list
Update free list to point at the new nodes next
Update the new nodes next to point at current node
Update the node prior to current node to point at the new node
Insert After Adds a node to the list immediately after a given node current node
There are four steps for this operation:
Get the node pointed to by the free list
Update free list to point at the new nodes next
Update the new nodes next to point at current nodenext
Update the node current node to point at the new node
Remove
Remove Removes a specific node current node There are four steps for this operation:
Get the node pointed to by current node
Update the node prior to current node to point at current nodenext
Update the new nodes next to point at list free
Update free list to point at the removed node
Clear Removes all nodes from a list and adds them to the free list. There are sev
eral methods to accomplish this. However, since we have linklists, we can do better than
repeatedly calling the remove function.
Functions to write
You probably noticed these overlap with the prior functions, but also with each other. We
will reuse our prior helper functions.
list find Write a struct node list findstruct node list head, int value which
finds the value and returns a pointer to that node. It should return a valid pointer if value
is found, or NULL if it is not.
list insert before Write a int list insert beforestruct node list head, struct
node free list, int reference, int value which first finds the node containing the
reference, and then performs an insert of value before as described above Use any of the
helper functions you have previously created. The function should return an int where is
success, and is failure.
list insert after Write a int list insert afterstruct node list head, struct
node free list, int reference, int value which first finds the node containing the
value, and then performs an insert after as described above Use any of the helper functions
you have previously created. The function should return an int where is success, and
is failure.
list remove Write a int list removestruct node list head, struct node free list,
int reference which first finds the node containing the value, and then removes that node
as described above Use any of the helper functions you have previously created. The func
tion should return an int where is success, and is failure.
list clear Write a void list clearstruct node list head, struct node free list
The list clear function removes all nodes from the list and return them to the free list.
main Extend the main function from the previous lab with the birf and c
operations described below.
The complete set of commands should be:
a for append; eg
a
Append an item to the list
e for prepend; eg
e
Prepend an item to the list
o for pop; eg
o
Pop an item from the list
b for insert before; eg
b
Finds the value given first argument and inserts the value second argument before
it
i for insert after; eg
i
Finds the value given first argument and inserts the value second argument after
it
f for find eg
f
Finds an item in the list and prints its memory location and value.
r for remove eg
r
Removes an item from the list.
c for clear eg
c
Removes all items from the list.
p for print all; eg
p
Print the list on a single line as with the following format: value value
value...
q to quit the program.
All cases should print the message success if the operation is successful, or fail if the
operation fails.
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