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

QUSINGLLYLL

Uploaded by

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

QUSINGLLYLL

Uploaded by

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

//application of linked list

//queue using linked list


//linear queue using linked list
#include<stdio.h>
#include<conio.h>
struct LQueue
{
int data;
struct LQueue*next;
};
typedef struct LQueue MyLQ;
int isempty(MyLQ*);
void enque(MyLQ *,int);
int deque(MyLQ*);
void display(MyLQ*);
void main()
{
int choice,n,q;
MyLQ * front=NULL;
MyLQ * rear=NULL;
clrscr();
do{
printf("\nMenu\n1. Insert\n2. Delete\n3. Dsiplay\n4.Exit\n. Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("\nEnter value to insert: ");
scanf("%d",&n);
enque(q,n);
printf("\n%d inserted to queue.",n);
break;
case 2:n=deque(q);
break;
case 3:display(q);
break;
case 4:printf("\nExiting...");
exit(0);
default:printf("\nInvalid choice,please try again.");
}
}while(choice<=4);
getch();
}
int isempty(MyLQ *q)
{
int front;
if(front==NULL)
printf("\nQueue is empty.");
return;
}
void enque(MyLQ *q,int n)
{
temp=(MyLQ*)malloc(sizeof(MyLQ));
printf("\nEnter element: ");
scanf("%d",temp->data);
if(front==NULL)
{
front=temp;
}
else
{
rear->next=temp;
}
rear=temp;
}
int deque(MyLQ *q)
{
if(front==NULL)
{
printf("\nQueue is empty.");
}
else
{
temp=front;
printf("\nDeleted element is %d.",temp->data);
front=front->next;
}
if(front==NULL)
{
rear=NULL;
}
free(temp);
}
void display(MyLQ *q)
{
if(front==NULL)
{
printf("\nQueue is empty.")
}
else
{
for(temp=front;temp!=NULL;temp=temp->next)
{
printf("%d\t",temp->data);
}
}
}

You might also like