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
icon
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.
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;
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar 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