0% found this document useful (0 votes)
150 views3 pages

Queue Using Linked List

The document describes a program to implement a queue using a linked list data structure in C. The program uses functions to insert items into the queue, delete items from the queue, and display the items currently in the queue. It provides a menu for the user to select these queue operations and includes the code for the functions to implement each operation using a linked list with front and rear pointers to track the first and last nodes.

Uploaded by

Sitaram Sds
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)
150 views3 pages

Queue Using Linked List

The document describes a program to implement a queue using a linked list data structure in C. The program uses functions to insert items into the queue, delete items from the queue, and display the items currently in the queue. It provides a menu for the user to select these queue operations and includes the code for the functions to implement each operation using a linked list with front and rear pointers to track the first and last nodes.

Uploaded by

Sitaram Sds
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/ 3

www.eazynotes.

com

Gursharan Singh Tatla

Page No. 1

QUEUE USING LINKED LIST


/****

Program to Implement Queue using Linked List

****/

#include<stdio.h>
struct node
{
int info;
struct node *link;
}*front = NULL, *rear = NULL;
void insert();
void delet();
void display();
int item;
main()
{
int ch;
do
{
printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
delet();
break;
case 3:
display();
break;
case 4:
exit(0);

www.eazynotes.com

Gursharan Singh Tatla

Page No. 2

default:
printf("\n\nInvalid choice. Please try again...\n");
}
} while(1);
getch();
}
void insert()
{
printf("\n\nEnter ITEM: ");
scanf("%d", &item);
if(rear == NULL)
{
rear = (struct node *)malloc(sizeof(struct node));
rear->info = item;
rear->link = NULL;
front = rear;
}
else
{
rear->link = (struct node *)malloc(sizeof(struct node));
rear = rear->link;
rear->info = item;
rear->link = NULL;
}
}
void delet()
{
struct node *ptr;
if(front == NULL)
printf("\n\nQueue is empty.\n");
else
{
ptr = front;
item = front->info;
front = front->link;
free(ptr);
printf("\nItem deleted: %d\n", item);
if(front == NULL)
rear = NULL;
}
}

www.eazynotes.com

Gursharan Singh Tatla

void display()
{
struct node *ptr = front;
if(rear == NULL)
printf("\n\nQueue is empty.\n");
else
{
printf("\n\n");
while(ptr != NULL)
{
printf("%d\t",ptr->info);
ptr = ptr->link;
}
}
}

Page No. 3

You might also like