0% found this document useful (0 votes)
3 views2 pages

Queue Using List

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Queue Using List

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

struct que

{
int item;
struct que *next;
};

struct que *front=NULL;


struct que *rear=NULL;
void ins(int);
void print(void);
int del(void);

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:

printf("\nThe Given List is\n");


print();
}
printf("\n Continue 1/0");
scanf("%d",&ch);
}while(ch==1);
}
void print(void)
{ struct que *t;
t=front;
while(front!=rear->next)
{
printf("%d ," ,front->item);
front=front->next;
}
front=t;
}

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;
}

You might also like