0% found this document useful (0 votes)
70 views4 pages

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)
70 views4 pages

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy