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:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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. 

int value;
value = NextItem(base_ptr);
printf("The first value of the list is d\n", value);
while (value !=0)
{
}
value= Next Item (NULL);
printf("The next value of the list is %d\n", value);
Figure 3
Transcribed Image Text:int value; value = NextItem(base_ptr); printf("The first value of the list is d\n", value); while (value !=0) { } value= Next Item (NULL); printf("The next value of the list is %d\n", value); Figure 3
45575WNHOFAWNHOS COLAGSWNT
2
W W N N N N NNNI
4
8
9
19
20
21
22
23
24
25
10
11
12
13
14
15
16
}
17
18 int main()
{
26
M
27
28
29
907
30
31
typedef struct item{
int payload;
struct item* next_element;
} item;
void AddNew (item *list_base, int payload)
{
}
while ((list_base->next_element) !=NULL)
(
list_base= (list_base->next_element);
}
item *new_element = (item*) malloc(sizeof (item))
(*new_element).payload = payload;
(*new_element) .next_element = NULL;
list_base->next_element = new_element;
char command;
item *list_base;
while (1)
(
printf("Please input your desired command: \n");
command
getchar();
/* Remainder of code that does something with the list depending on the command.
This contains code functionality to add elements to list, remove elements,
save list into a file, terminate program, etc.*/
}
return 0;
Figure 2
Transcribed Image Text:45575WNHOFAWNHOS COLAGSWNT 2 W W N N N N NNNI 4 8 9 19 20 21 22 23 24 25 10 11 12 13 14 15 16 } 17 18 int main() { 26 M 27 28 29 907 30 31 typedef struct item{ int payload; struct item* next_element; } item; void AddNew (item *list_base, int payload) { } while ((list_base->next_element) !=NULL) ( list_base= (list_base->next_element); } item *new_element = (item*) malloc(sizeof (item)) (*new_element).payload = payload; (*new_element) .next_element = NULL; list_base->next_element = new_element; char command; item *list_base; while (1) ( printf("Please input your desired command: \n"); command getchar(); /* Remainder of code that does something with the list depending on the command. This contains code functionality to add elements to list, remove elements, save list into a file, terminate program, etc.*/ } return 0; Figure 2
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education