0% found this document useful (0 votes)
22 views2 pages

Queue Using Templates

This document contains a C++ implementation of a queue data structure using templates. It includes methods for inserting elements at the rear, deleting elements from the front, checking if the queue is empty or full, and displaying the queue contents. The main function provides a simple menu for user interaction with the queue operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Queue Using Templates

This document contains a C++ implementation of a queue data structure using templates. It includes methods for inserting elements at the rear, deleting elements from the front, checking if the queue is empty or full, and displaying the queue contents. The main function provides a simple menu for user interaction with the queue operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

using namespace std;


template<class Type>
class queue
{
Type q[10];
int front=-1,rear=-1,size;
public:
queue()
{
cout<<"\n enter the size ::";
cin>>size;
}
bool isempty()
{
if(front==-1&&rear==-1)
return true;
else
return false;
}
bool isfull()
{
if(rear==size-1)
return true;
else
return false;
}
void rearinsert(Type item)
{
if(isfull())
cout<<"\n queue is full!!";
else if(front==-1&&rear==-1)
{
front=rear=0;
q[rear]=item;
}
else
{
rear++;
q[rear]=item;
}
}
void frontdelete()
{

if(isempty())
cout<<"\n queue is empty!!";
else if(front==rear)
{
cout<<"\n deleted element is::"<<q[front];
front=rear=-1;
}
else
{
cout<<"\n deleted element is::"<<q[front];
front++;
}
}
void display()
{
int i;
if(isempty())
cout<<"\n queue is empty!!";
else
{
cout<<"\n items in the queue::";
for(i=front;i<=rear;i++)
cout<<q[i]<<"\t";
}

};
int main()
{
cout<<"\n queue using templates!!";
queue<int>obj;
int item;
int choice;
while(1)
{
cout<<"\n1...insert\t2...delete\t3...delete\tany key to exit:";
cout<<"\n enter the choice::";
cin>>choice;
switch(choice)
{
case 1: cout<<"\n enter the item::";
cin>>item;
[Link](item);
break;
case 2: [Link]();
break;
case 3:[Link]();
break;
default:cout<<"\n program is ended";
exit(0);
}
}
return 0;
}

You might also like