Do the following for a linkedlist based queue a Declare a st

Do the following for a linked-list based queue: a) Declare a structure consisting of a name (customer), and an ID (order number), and a pointer to the next node. b) Write an Enqueue function for inserting an element in the queue.

Solution

#include<stdio.h>
#include<stdlib.h>
struct custmor
{
int id;
struct custmor* next;
}*rear, *front;

void push(int value)
{
struct custmor *temp;
temp=(struct custmor *)malloc(sizeof(struct custmor));
temp->id=value;
if (front == NULL)
{
front=temp;
front->next=NULL;
rear=front;
}
else
{
front->next=temp;
front=temp;
front->next=NULL;
}
}

void display()
{
struct custmor *var=rear;
if(var!=NULL)
{
printf(\"\ Elements are as: \");
while(var!=NULL)
{
printf(\"\\t%d\",var->id);
var=var->next;
}
printf(\"\ \");
}
else
printf(\"\ Queue is Empty\");
}

int main()
{
int i=0;
front=NULL;
printf(\" \ 1. insert to Queue\");
printf(\" \ 2. display from Queue\");
printf(\" \ 3. Exit\ \");
while(1)
{
printf(\" \ Choose Option: \");
scanf(\"%d\",&i);
switch(i)
{
case 1:
{
int value;
printf(\"\ Enter a valueber to push into Queue: \");
scanf(\"%d\",&value);
push(value);
display();
break;
}
case 2:
{
display();
break;
case 3:
{
exit(0);
}
default:
{
printf(\"\ wrong choice for operation\");
}
}
}
}
}

 Do the following for a linked-list based queue: a) Declare a structure consisting of a name (customer), and an ID (order number), and a pointer to the next nod
 Do the following for a linked-list based queue: a) Declare a structure consisting of a name (customer), and an ID (order number), and a pointer to the next nod

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site