Queue Implementation in Data Structure using C++
by TechVidvan Team
Program 1
#include<iostream>
#define MAXSIZE 10
#define clrscr() system("cls")
using namespace std;
class Myqueue
{
private :
int rear,front;
int queue[MAXSIZE];
public:
Myqueue()
{
rear=-1;
front=0;
}
void insert();
void delete1();
void display();
};
void Myqueue::insert()
{
int n;
if(rear==MAXSIZE-1)
cout<<"\nQueue is overflow";
else
{
cout<<"\nEnter an element:";
cin>>n;
rear++;
queue[rear]=n;
}
}
void Myqueue::delete1()
{
int n;
if(front>rear)
cout<<"\nQueue is empty";
else
{
n=queue[front];
front++;
cout<<"\nDeleted element is:"<<n;
}
}
void Myqueue::display()
{
int i;
if(front>rear)
cout<<"\nQueue is empty";
else
{
cout<<"\n QUEUE Elements: " ;
for(i=rear;i>=front;i--)
cout<<" "<<queue[i];
}
}
int main()
{
clrscr();
int choice;
Myqueue M;
do
{
cout<<"\n--------------Queue Menu---------------------";
cout<<"\n1. INSERT";
cout<<"\n2. DELETE";
cout<<"\n3. DISPLAY";
cout<<"\n4.EXIT";
cout<<"\n------------------------------------------------";
cout<<"\nEnter your choice";
cin>>choice;
switch(choice)
{
case 1:M.insert();break;
case 2:M.delete1();break;
case 3:M.display();break;
case 4:break;
default:cout<<"\nInvalid choice";
}
}while(choice!=4);
return 0;
}
Tags: cppdata structure using c++data structure with c++dsa using c++dsa using c++ practicaldsa using c++ programqueue implementation in dsa using c++queue in dsa using c++queue in dsa with c++
TechVidvan Team
TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.