Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Queue Using Link List

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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