Complete the function Add to add a new Node to a FIFO queue


Complete the function Add() to add a new Node to a FIFO queue, as shown. The function is passed a pointer to the new node as shown. Required queue variables (i.e. pHead and pTail) may be assumed to be global variables that can be accessed by the Add() function).

Solution

Here is the code for you:

Node *p = malloc(sizeof(Node));
Add(p);

Add(Node *p)
{
int temp;
printf(\"Enter the value to insert: \");
scanf(\"%d\", &temp);
p->info = temp;
p->next = NULL;
if(pTail == NULL)       //If there are no nodes in the Queue
pTail = pHead = p;   //Add this single node itself, and make the head and tail point to this node.
else   //If there are some nodes in the queue.
{
p->next = pTail;   //Add this as the last element in the queue, and make the last element come after this p.
pTail = p;           //Make pTail point to this node p.
}
}

If you need any refinements, just get back to me.

 Complete the function Add() to add a new Node to a FIFO queue, as shown. The function is passed a pointer to the new node as shown. Required queue variables (i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site