// Queue Implementation   Using Linked List.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<alloc.h>
void insert();
void delete();
void display();
typedef struct queue{
			int data;
			struct queue *link;
			}*node;
node front,rear,q;
int item;
main()
{
	int ch;
	char choice='y';
	clrscr();
	while(choice=='y')
	{
//		clrscr();
		printf(" \n\n\n\t\t  Q U E U E   O P E R A T I O N\n");
		printf("\t\t\t  1.I N S E R T I O N \n");
		printf("\t\t\t  2.D E L E T I O N\n");
		printf("\t\t\t  3.E X I T\n");
		printf("Enter Your choice:");
		scanf("%d",&ch);
		switch(ch)
			{
			case 1:
				insert();
				break;
			case 2:
				delete();
				break;
			case 3:
				exit(0);
			default:
				printf("Invalid Choice\n Retry:");
				break;
			}
		display();
		printf("\nDo you Want To Continue:");
		scanf("%c",&choice);
		choice=getchar();
	}
getch();
}

void insert()
{
	printf("Enter The Data To Be Inserted:");
	scanf("%d",&item);
	q=(node *)malloc(sizeof(node));
	q->data=item;
	q->link=NULL;
	front->link=q;
	if(rear==NULL)
		rear=q;
	front=q;
	return;
}
void delete()
{
	if(rear==NULL)
	{
		printf("\n The Queue Underflows.");
		return;
	}
	q=rear;
	item=q->data;
	rear=q->link;
	free(q);
	printf("\nThe Deleted Item Is:%d",item);
	return;
}
void display()
{
	q=rear;
	if(q==NULL)
	{
		printf("\n The Queue Is Empty.");
		return;
	}
	printf("\nThe Contents Of The Queue Is:\n");
	while(q!=NULL)
	{
		printf("%d\t",q->data);
		q=q->link;
	}
	return;
}
