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

Queue_Program

This document contains a C program that implements a simple queue using an array with a maximum size of 5. It provides functionalities to insert, delete, and display elements in the queue, along with a main menu for user interaction. The program handles overflow and underflow conditions appropriately.

Uploaded by

patelsaab2323
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Queue_Program

This document contains a C program that implements a simple queue using an array with a maximum size of 5. It provides functionalities to insert, delete, and display elements in the queue, along with a main menu for user interaction. The program handles overflow and underflow conditions appropriately.

Uploaded by

patelsaab2323
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>

#include<stdlib.h>

#define maxsize 5

void insert();

void delete();

void display();

int front = -1, rear = -1;

int queue[maxsize];

void main ()

int choice;

while(choice != 4)

printf("\n*************************Main
Menu*****************************\n");

printf("\
n============================================
=====================\n");

printf("\n1.insert an element\n2.Delete an element\n3.Display the


queue\n4.Exit\n");

printf("\nEnter your choice ?");

scanf("%d",&choice);

switch(choice)

case 1:

insert();

break;

case 2:

delete();

break;
case 3:

display();

break;

case 4:

exit(0);

break;

default:

printf("\nEnter valid choice??\n");

void insert()

int item;

printf("\nEnter the element\n");

scanf("\n%d",&item);

if(rear == maxsize-1)

printf("\nOVERFLOW\n");

return;

if(front == -1 && rear == -1)

front = 0;

rear = 0;

else

rear = rear+1;
}

queue[rear] = item;

printf("\nValue inserted ");

void delete()

int item;

if (front == -1 || front > rear)

printf("\nUNDERFLOW\n");

return;

else

item = queue[front];

if(front == rear)

front = -1;

rear = -1 ;

else

front = front + 1;

printf("\nvalue deleted ");

}
}

void display()

int i;

if(rear == -1)

printf("\nEmpty queue\n");

else

{ printf("\nprinting values .....\n");

for(i=front;i<=rear;i++)

printf("\n%d\n",queue[i]);

You might also like