1. Given the attached program code, answer the following: (a) Match each function name with its task. Function Name Task F1 Insert a node at the front of the list. Insert a node after a given node. Delete a node in a specific position. F2 F3 F4 Insert a node at the end of the list. Create the first node in the list. Display all the nodes of the list. F5 F6 (b) What is the result of program execution with the data given in main( ) (c) Write a function to count the number of nodes in the list.
1. Given the attached program code, answer the following: (a) Match each function name with its task. Function Name Task F1 Insert a node at the front of the list. Insert a node after a given node. Delete a node in a specific position. F2 F3 F4 Insert a node at the end of the list. Create the first node in the list. Display all the nodes of the list. F5 F6 (b) What is the result of program execution with the data given in main( ) (c) Write a function to count the number of nodes in the list.
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
Related questions
Question
I want to solve the question 4
The program code will help you to solve the question 4
![Question4 (Linked List):
1. Given the attached program code, answer the following:
(a) Match each function name with its task.
Function Name
Task
F1
Insert a node at the front of the list.
Insert a node after a given node.
Delete a node in a specific position.
F2
F3
F4
Insert a node at the end of the list.
F5
Create the first node in the list.
Display all the nodes of the list.
F6
(b) What is the result of program execution with the data given in main().
(c) Write a function to count the number of nodes in the list.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F78314d2f-85eb-442d-a348-a0a13b36acc1%2F49340d06-fb61-4e59-bdaf-ddd43dcc53ad%2F246mvo_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Question4 (Linked List):
1. Given the attached program code, answer the following:
(a) Match each function name with its task.
Function Name
Task
F1
Insert a node at the front of the list.
Insert a node after a given node.
Delete a node in a specific position.
F2
F3
F4
Insert a node at the end of the list.
F5
Create the first node in the list.
Display all the nodes of the list.
F6
(b) What is the result of program execution with the data given in main().
(c) Write a function to count the number of nodes in the list.
![The program code:
#include <iostream>
// ***** F5 ****
using namespace
std; struct Node {
int data;
void F5 (int value, int position)
Node *newNode, *curr, *pred,
*succ, *head;
Node* next;};
// ***** F1 ****
void F1( int n)
newNode = new Node;
newNode->data = value;
Node *head-new Node;
newNode->next = NULL;
head->data = n;
curr=head;
for (int i=1;i<=position; i++)
(pred-curr; curr = curr->next;}
head->next =NULL;)
// ***** F2 ****
void F2 (int value)
curr=head;
Node *newNode, *head, *curr;
newNode - new Node;
for (int i-1;i<=position+l;i++)
{succ-curr;curr curr->next;}
pred->next-newNode; newNode->next
newNode-
>data - value;
newNode->next =
succ;
NULL;
if (head=NULL)
// ***** F6 ****
void F6 (int
position)
Node
head = newNode;
else
{ curr = head;
while
*curr, *pred, *succ, *head;
curr=head;
(curr->next!=NULL)
if (position==1)
(curr = curr->next; head-curr;}
curr = curr->next;
curr-
>next = newNode;
else
for (int i=1;i<=position-1;i++)
(pred-curr; curr curr->next;}
// ***** F3 ****
void F3 ()
(Node *curr; Node
curr=head;
for (int i-1;i<=position+1;i++)
(succ=curr; curr curr->next;}
pred->next = succ;
*head;
curr = head;
while (curr!=NULL)
{cout << curr->data <<
->
";
= curr->next; }
curr
// ***** main
**** int main ()
cout <<
"NULL";
cout <<
endl;
{ F1 (5); F2 (10);
F2 (15); F2 (20);
F2 (25); F4 (-20);
F3 ();
// ***** F4 ****
void F4 (int value)
( Node *newNode, *head,
F5 (500, 3) ; F3 ();
F5 (600,3); F3 ();
F6 (1); F3 ();
F6 (1) ; F3 ();
*curr;
newNode - new Node;
newNode->data = value;
newNode->next - NULL; if
(head!=NULL)
>next-head;
newNode-
F6 (4); F3 ();
return 0;
head=newNode;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F78314d2f-85eb-442d-a348-a0a13b36acc1%2F49340d06-fb61-4e59-bdaf-ddd43dcc53ad%2F7fryoh_processed.jpeg&w=3840&q=75)
Transcribed Image Text:The program code:
#include <iostream>
// ***** F5 ****
using namespace
std; struct Node {
int data;
void F5 (int value, int position)
Node *newNode, *curr, *pred,
*succ, *head;
Node* next;};
// ***** F1 ****
void F1( int n)
newNode = new Node;
newNode->data = value;
Node *head-new Node;
newNode->next = NULL;
head->data = n;
curr=head;
for (int i=1;i<=position; i++)
(pred-curr; curr = curr->next;}
head->next =NULL;)
// ***** F2 ****
void F2 (int value)
curr=head;
Node *newNode, *head, *curr;
newNode - new Node;
for (int i-1;i<=position+l;i++)
{succ-curr;curr curr->next;}
pred->next-newNode; newNode->next
newNode-
>data - value;
newNode->next =
succ;
NULL;
if (head=NULL)
// ***** F6 ****
void F6 (int
position)
Node
head = newNode;
else
{ curr = head;
while
*curr, *pred, *succ, *head;
curr=head;
(curr->next!=NULL)
if (position==1)
(curr = curr->next; head-curr;}
curr = curr->next;
curr-
>next = newNode;
else
for (int i=1;i<=position-1;i++)
(pred-curr; curr curr->next;}
// ***** F3 ****
void F3 ()
(Node *curr; Node
curr=head;
for (int i-1;i<=position+1;i++)
(succ=curr; curr curr->next;}
pred->next = succ;
*head;
curr = head;
while (curr!=NULL)
{cout << curr->data <<
->
";
= curr->next; }
curr
// ***** main
**** int main ()
cout <<
"NULL";
cout <<
endl;
{ F1 (5); F2 (10);
F2 (15); F2 (20);
F2 (25); F4 (-20);
F3 ();
// ***** F4 ****
void F4 (int value)
( Node *newNode, *head,
F5 (500, 3) ; F3 ();
F5 (600,3); F3 ();
F6 (1); F3 ();
F6 (1) ; F3 ();
*curr;
newNode - new Node;
newNode->data = value;
newNode->next - NULL; if
(head!=NULL)
>next-head;
newNode-
F6 (4); F3 ();
return 0;
head=newNode;
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education