answersLogoWhite

0

#include<iostream.h>

#include<conio.h>

#include<process.h>

#define SIZE 10

int queue[SIZE];

int front=-1,rear=-1;

void insert();

void del();

void display();

void main()

{

int ch;

do

{

clrscr();

cout<<"\nMAIN MENU."<<endl;

cout<<"\n1. Insert."<<endl;

cout<<"\n2. Delete."<<endl;

cout<<"\n3. Display."<<endl;

cout<<"\n4 Exit.\n"<<endl;

cout<<"\nEnter your choice.(1-4) : ";

cin>>ch;

switch(ch)

{

case 1 : insert();

break;

case 2 : del();

break;

case 3 : display();

break;

case 4 : exit(0);

default : cout<<"\nInvalid Choice.";

}

getch();

}

while(1);

}

void insert()

{

int val;

if(rear==SIZE-1)

{

cout<<"OVERFLOW."<<endl;

return;

}

cout<<"\nEnter the value : ";

cin>>val;

if(rear==front)

{

rear++;

front++;

queue[rear]=val;

}

else

{

rear++;

queue[rear]=val;

}

}

void del()

{

if(front==-1)

{

cout<<"\nQueue is empty.";

return;

}

if(front==rear)

front=rear=-1;

else

front++;

}

void display()

{

int front_vir=rear;

if(front==-1)

{

cout<<"\nQueue is empty.\n";

return;

}

while(front_vir<=rear)

{

cout<<queue[front_vir]<< " ";

front_vir++;

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?