de. Answer the questions below: i. Briefly describe the purpose of the function AddNew, including a short description of the function’s parameters. ii. Explain the semantics of the following lines of code in Figure 2: 12, 14, 15, as well as the purpose of the while loop, defined in lines 8-11. ii. Write the code for the function defined by the following prototype: int NextItem(item *); This function should work in the following manner:
The code shown in Figure 2 is part of an application that provides functionality to
operate on a linked list. You can assume that all required libraries will be included in
the final version of the source code. Answer the questions below:
i. Briefly describe the purpose of the function AddNew, including a short description
of the function’s parameters.
ii. Explain the semantics of the following lines of code in Figure 2: 12, 14, 15, as well
as the purpose of the while loop, defined in lines 8-11.
ii. Write the code for the function defined by the following prototype:
int NextItem(item *);
This function should work in the following manner:
• When the function is called, it returns the payload of the first element of the list
referenced in the parameter.
• Successive calls to the function when using a NULL pointer (e.g.
NextItem(NULL); ) will return the payloads of the previously chosen list in
order, one by one in each call.
• This functionality should continue until a new pointer is used as a parameter; in
which case the function starts again from the beginning of the requested list.
• When the list runs out, or in case of incorrect input, the function should return a
value of 0.
• A common usage case of the function NextItem() can be seen in Figure 3.
Step by step
Solved in 4 steps