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...


I want to solve the question 4


The program code will help you to solve the question 4


Question4 (Linked List):<br>1. Given the attached program code, answer the following:<br>(a) Match each function name with its task.<br>Function Name<br>Task<br>F1<br>Insert a node at the front of the list.<br>Insert a node after a given node.<br>Delete a node in a specific position.<br>F2<br>F3<br>F4<br>Insert a node at the end of the list.<br>F5<br>Create the first node in the list.<br>Display all the nodes of the list.<br>F6<br>(b) What is the result of program execution with the data given in main().<br>(c) Write a function to count the number of nodes in the list.<br>

Extracted 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:<br>#include <iostream><br>// ***** F5 ****<br>using namespace<br>std; struct Node {<br>int data;<br>void F5 (int value, int position)<br>Node *newNode, *curr, *pred,<br>*succ, *head;<br>Node* next;};<br>// ***** F1 ****<br>void F1( int n)<br>newNode = new Node;<br>newNode->data = value;<br>Node *head-new Node;<br>newNode->next = NULL;<br>head->data = n;<br>curr=head;<br>for (int i=1;i<=position; i++)<br>(pred-curr; curr = curr->next;}<br>head->next =NULL;)<br>// ***** F2 ****<br>void F2 (int value)<br>curr=head;<br>Node *newNode, *head, *curr;<br>newNode - new Node;<br>for (int i-1;i<=position+l;i++)<br>{succ-curr;curr curr->next;}<br>pred->next-newNode; newNode->next<br>newNode-<br>>data - value;<br>newNode->next =<br>succ;<br>NULL;<br>if (head=NULL)<br>// ***** F6 ****<br>void F6 (int<br>position)<br>Node<br>head = newNode;<br>else<br>{ curr = head;<br>while<br>*curr, *pred, *succ, *head;<br>curr=head;<br>(curr->next!=NULL)<br>if (position==1)<br>(curr = curr->next; head-curr;}<br>curr = curr->next;<br>curr-<br>>next = newNode;<br>else<br>for (int i=1;i<=position-1;i++)<br>(pred-curr; curr curr->next;}<br>// ***** F3 ****<br>void F3 ()<br>(Node *curr; Node<br>curr=head;<br>for (int i-1;i<=position+1;i++)<br>(succ=curr; curr curr->next;}<br>pred->next = succ;<br>*head;<br>curr = head;<br>while (curr!=NULL)<br>{cout << curr->data <<<br>-><br>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; "/>
Extracted text: The program code: #include // ***** 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;
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here