I still don't get it, so I'll try to understand the very simple. Let's assume I have queue and it has only tow nodesThis is a verbal description of the code you need to write. Turn it into pseudo-code or actual functions in C.
C:
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int n;
struct Node *next;
}Node;
int main()
{
Node *Head = NULL;
Node *Tail = NULL;
Node *Current = NULL;
Head = malloc(sizeof(Head));
Tail = malloc(sizeof(Tail));
if (Head == NULL)
printf ("Memory not Allocated \n");
else
printf ("Memory Allocated \n");
Head->n = 0;
Head->next = NULL;
Tail->n = 0;
Tail->next= NULL;
for (Current = Head; Current!= NULL; Current = Current->next)
{
printf("%d ", Current->n);
}
return 0;
}
I have empty queue I do not know how to do the en queue operationTo add an element, you allocate memory for the element. And you save a pointer to this memory. You traverse the existing queue until the next pointer is null. Then, you change the next pointer ofthe last element to the pointer of the newly allocated memory. There’s a little processing required to account for the very first element.
Will you advice me what i should do next for en queue operation in program ?