Queue Using Link List
Queue Using Link List
Queue Using Link List
#include<stdio.h>
#include<conio.h>
#define MAX 5
struct queue
int info;
};
q *top,*ptr,*p;
void insert();
void delet();
void display();
void main() {
int ch;
do
scanf("%d",&ch);
switch(ch)
case 1: insert();
break;
case 2: delet();
break;
case 3: display();
break;
case 4: exit(0);
}while(ch!=4); }
void insert() {
int val,count;
for(count=0,p=top;p!=NULL;count++)
p=p->next;
if(count==MAX)
else {
ptr=(q*)malloc(sizeof(q));
scanf("%d",&val);
ptr->info=val;
ptr->next=top;
top=ptr;
printf("\nInsertion is successful\n");
}}
void delet()
if(top==NULL)
else {
p=top;
top=top->next;
free(p);
printf("\nDeletion is successful\n");
} }
void display()
{ int i, count;
if(top==NULL)
printf("\nQueue is empty\n");
else { printf("\nQueue:\n");
p=top;
while(p!=NULL) {
printf("%d\n",p->info);
p=p->next; } }
for(count=0,p=top;p!=NULL;count++)
p=p->next;
if(count==MAX)
printf("\nQueue is Full\n"); }