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

Q LL

The document implements a queue using a linked list data structure in C. It includes functions to enqueue, dequeue and display elements in the queue. The main function runs a loop taking user input to perform these queue operations.

Uploaded by

Simrah Hafeez
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)
11 views2 pages

Q LL

The document implements a queue using a linked list data structure in C. It includes functions to enqueue, dequeue and display elements in the queue. The main function runs a loop taking user input to perform these queue operations.

Uploaded by

Simrah Hafeez
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

#include<stdio.

h>
#include<conio.h>

struct Node
{
int data;
struct Node *next;
}*front = NULL,*rear = NULL;

void enq(int);
void deq();
void display();

void main()
{
int choice,data;
while(1)
{
printf("1. Enq\n2. Deq\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the value to be insert: ");
scanf("%d", &data);
enq(data);
break;
case 2:
deq();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Wrong choice\n");
}
}
}
void enq(int data)
{
struct Node *ptr;
ptr = (struct Node*)malloc(sizeof(struct Node));
ptr->data=data;
ptr->next=NULL;
if(front==NULL)
front=rear=ptr;
else
{
rear->next=ptr;
rear=ptr;
}
}
void deq()
{
if(front==NULL)
printf("Queue is Empty\n");
else
{
struct Node *ptr=front;
front=front->next;
printf("Deleted element %d\n", ptr->data);
free(ptr);
}
}
void display()
{
if(front==NULL)
printf("Queue is Empty\n");
else
{
struct Node *ptr = front;
while(ptr->next!=NULL)
{
printf("%d ",ptr->data);
ptr=ptr->next;
}
printf("%d \n",ptr->data);
}
}

You might also like