0% found this document useful (0 votes)
58 views

Queue Using Link List

This program implements a queue using a linked list data structure in C. It defines functions to insert, delete, and display elements in the queue. The main function contains a menu loop that calls these functions based on the user's selection and exits when 4 is selected. The insert function adds elements to the rear of the queue until it is full. The delete function removes elements from the front of the queue. And the display function prints out the current queue elements.

Uploaded by

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

Queue Using Link List

This program implements a queue using a linked list data structure in C. It defines functions to insert, delete, and display elements in the queue. The main function contains a menu loop that calls these functions based on the user's selection and exits when 4 is selected. The insert function adds elements to the rear of the queue until it is full. The delete function removes elements from the front of the queue. And the display function prints out the current queue elements.

Uploaded by

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

PROGRAM NO:-7

Aim:- To implement Queue using linked list.


Source code:

#include<stdio.h>

#include<conio.h>

#define MAX 5

struct queue

int info;

struct queue *next;

};

typedef struct queue q;

q *top,*ptr,*p;

void insert();

void delet();

void display();

void main() {

int ch;

printf("Queue Menu:\n1. INSERT\n2. DELETE\n3. DISPLAY\n4. EXIT\n");

do

printf("\nEnter choice: ");

scanf("%d",&ch);
switch(ch)

case 1: insert();

break;

case 2: delet();

break;

case 3: display();

break;

case 4: exit(0);

default: printf("Invalid selection.....\n");

}while(ch!=4); }

void insert() {

int val,count;

for(count=0,p=top;p!=NULL;count++)

p=p->next;

if(count==MAX)

printf("\nOVERFLOW : Queue is Full\n");

else {

ptr=(q*)malloc(sizeof(q));

printf("\nEnter the value to insert in queue: ");

scanf("%d",&val);

ptr->info=val;

ptr->next=top;
top=ptr;

printf("\nInsertion is successful\n");

}}

void delet()

if(top==NULL)

printf("\nUNDERFLOW : Queue is empty\n");

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

You might also like