Queue Using List
Queue Using List
{
int item;
struct que *next;
};
void main(void)
{ int opt,ch,y;
clrscr();
do
{
clrscr();
printf("\n1. Insert\n");
printf("\n2. Delete\n");
printf("\n3. Print\n");
printf("\n4. Exit\n");
printf("\n\n\t Enter your Choice\n");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter item to Insert\n");
scanf("%d", &y);
ins(y);
break;
case 2:
y=del();
printf("Pushed item is : %d" ,y);
break;
case 3:
void ins(int x)
{
struct que *r;
r=(struct que*)malloc(sizeof(struct que));
r->item=x;
r->next=NULL;
if(front==NULL)/*FIRST TIME TO FRONT*/
{
rear=front=r;
}
else
{
rear->next=r;
rear=r;
}
return;
}
int del(void)
{
int x;
if(rear==NULL)
{
printf("Empty Queue");
exit(0);
}
else
{
Temp=front
x=front->item;
front=front->next;
free(temp)
if (front==NULL)
rear=NULL
}
return x;
}