#include <stdio.h>
#include <stdlib.h>
struct node
{
int info;
struct node *link;
};
typedef struct node* NODE;
NODE insert_rear(int ,NODE );
NODE delete_front(NODE );
void display(NODE );
int main()
{
int ch,item;
NODE first;
first=NULL;
while(1)
{
scanf("%d",&ch);
switch (ch)
{
case 1:
scanf("%d",&item);
first=insert_rear(item,first);
break;
case 2:
first=delete_front(first);
break;
case 3:
display(first);
break;
case 4:exit(0);
default:
printf("Invalid Choice");
}
}
}
NODE insert_rear(int item,NODE first)
{
NODE temp,cur;
temp=(struct node*)malloc(1*sizeof(struct node));
temp->info=item;
temp->link=NULL;
if(first==NULL)
{
return temp;
}
cur=first;
while(cur->link!=NULL)
{
cur=cur->link;
}
cur->link=temp;
return first;
}
NODE delete_front(NODE first)
{
NODE temp;
if(first==NULL)
{
printf("\nQUEUE UNDERFLOW - No nodes to delete\n");
return NULL;
}
temp=first;
first=first->link;
printf("\nThe DEQUEUED Node VAL = %d",temp->info);
free(temp);
return first;
}
void display(NODE first)
{
NODE temp=first;
if(first==NULL)
{
printf("\nEmpty QUEUE - NOTHING TO DISPLAY");
return;
}
printf("\nTHE ELEMENTS OF QUEUE ARE -\n");
while(temp!=NULL)
{
printf("%d ",temp->info);
temp=temp->link;
printf(" ->");
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: