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

Queue

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

Queue

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

#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)

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

prin ("\n=================================================================\n");

prin ("\[Link] an element\[Link] an element\[Link] the queue\[Link]\n");

prin ("\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:

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

void insert()

int item;

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

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

if(rear == maxsize-1)

prin ("\nOVERFLOW\n");

return;

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

front = 0;

rear = 0;

else

rear = rear+1;

queue[rear] = item;

prin ("\nValue inserted ");

void delete()

{
int item;

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

prin ("\nUNDERFLOW\n");

return;

else

item = queue[front];

if(front == rear)

front = -1;

rear = -1 ;

else

front = front + 1;

prin ("\nvalue deleted ");

void display()

int i;

if(rear == -1)

prin ("\nEmpty queue\n");


}

else

{ prin ("\nprin ng values .....\n");

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

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

You might also like