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

C++ Queue Implementation Example

The document contains a C++ program that implements a queue data structure with basic operations such as enqueue, dequeue, and display. It defines a Queue class with methods to insert and remove elements, as well as to display the current elements in the queue. The program includes a menu-driven interface for user interaction to perform these operations.

Uploaded by

siddkamble2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

C++ Queue Implementation Example

The document contains a C++ program that implements a queue data structure with basic operations such as enqueue, dequeue, and display. It defines a Queue class with methods to insert and remove elements, as well as to display the current elements in the queue. The program includes a menu-driven interface for user interaction to perform these operations.

Uploaded by

siddkamble2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

PROGRAM ON QUEUE:-

#include<iostream.h>

#include<conio.h>

#define MAX 5

class Queue{

int arr[MAX];

int front,rear;

public:

Queue(){

front= -1;

rear=-1;

void enqueue(int x){

if(rear==MAX-1)

cout<<"\nQueue Overflow!";

else{

if(front==-1)

front=0;

rear++;

arr[rear]=x;

cout<<"\nInserted"<< x <<"into the queue.";

void dequeue(){

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

cout<<"\nQueue Under low!;

else{
cout<<"\nDeleted element:"<<arr[front];

front++;

void display(){

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

cout<<"\nQueue is empty!";

else {

cout<<"\nQueue elements are:\n";

int i=front;

while (i<=rear);{

cout<<arr[i]<<" ";

};

void main(){

clrscr();

Queue q;

int choice,val;

do{

cout<<"\n\n--Queue Menu ---";

cout<<"\[Link]";

cout<<"\[Link]";

cout<<"\[Link]";

cout<<"\[Link]";

cout<<"\nEnter your choice:";


cin>>choice;

switch(choice){

case 1:

cout<<"Enter value in enqueue:";

cin>>val;

[Link](val);

break;

case 2:

[Link]();

break;

case 3:

[Link]();

break;

case 4:

cout<<"\nExiting...";

break;

default:

cout<<"\ninvalid choice!";

}while(choice !=4);

getch();

Output:-

You might also like