//c++ code
#include<iostream>
using namespace std;
#include<conio.h>
#include<process.h>
template<class T>
class Queue
{
private:
int front,rear;
T *queue;
int maxsize;
public:
Queue(int maxqueuesize)
{
front=0;
rear=-1;
maxsize=maxqueuesize;
queue=new T[maxsize];
}
~Queue()
{
delete[] queue;
}
int isempty();
int isfull();
void insertion();
void deletion();
void _front();
void _rear();
void display();
};
template<class T>
int Queue<T>::isempty()
{
if(front==0&&rear==-1)
return 1;
else
return 0;
}
template<class T>
int Queue<T>::isfull()
{
if(rear==maxsize-1)
return 1;
else
return 0;
}
template<class T>
void Queue<T>::_front()
{
if(isempty())
cout<<"\n queue is empty.............";
else
cout<<"\n front element of the queue is:"<<queue[front];
}
template<class T>
void Queue<T>::_rear()
{
if(isempty())
cout<<"\n queue is empty.............";
else
cout<<"\n rear element of the queue is:"<<queue[rear];
}
template<class T>
void Queue<T>::insertion()
{
T ele;
if(isfull())
cout<<"\n queue is full........";
else
{
cout<<"\n enter the element do u want to insert :";
cin>>ele;
queue[++rear]=ele;
}
}
template<class T>
void Queue<T>::deletion()
{
if(isempty())
cout<<"\n queue is empty........";
else
cout<<"\n the deleted element of the queue is :"<<queue[front++];
}
template<class T>
void Queue<T>::display()
{
if(isempty())
cout<<"\n queue is empty.........";
else
{
cout<<"\n queue elements are :";
for(int i=front;i<=rear;i++)
{
cout<<"\t"<<queue[i];
}
}
}
int main()
{
int ch;
Queue<int> q(10);
do
{
cout<<"\n 1.insertion \n 2.deletion \n 3.front \n 4.rear \n 5.display \n 6.exit \n";
cout<<"enter ur choice:";
cin>>ch;
switch(ch)
{
case 1:
q.insertion();
break;
case 2:
q.deletion();
break;
case 3:
q._front();
break;
case 4:
q._rear();
break;
case 5:
q.display();
break;
case 6:
_exit(0);
}
}while(ch<=6);
_getch();
return 0;
}
#include<iostream>
using namespace std;
#include<conio.h>
#include<process.h>
template<class T>
class Queue
{
private:
int front,rear;
T *queue;
int maxsize;
public:
Queue(int maxqueuesize)
{
front=0;
rear=-1;
maxsize=maxqueuesize;
queue=new T[maxsize];
}
~Queue()
{
delete[] queue;
}
int isempty();
int isfull();
void insertion();
void deletion();
void _front();
void _rear();
void display();
};
template<class T>
int Queue<T>::isempty()
{
if(front==0&&rear==-1)
return 1;
else
return 0;
}
template<class T>
int Queue<T>::isfull()
{
if(rear==maxsize-1)
return 1;
else
return 0;
}
template<class T>
void Queue<T>::_front()
{
if(isempty())
cout<<"\n queue is empty.............";
else
cout<<"\n front element of the queue is:"<<queue[front];
}
template<class T>
void Queue<T>::_rear()
{
if(isempty())
cout<<"\n queue is empty.............";
else
cout<<"\n rear element of the queue is:"<<queue[rear];
}
template<class T>
void Queue<T>::insertion()
{
T ele;
if(isfull())
cout<<"\n queue is full........";
else
{
cout<<"\n enter the element do u want to insert :";
cin>>ele;
queue[++rear]=ele;
}
}
template<class T>
void Queue<T>::deletion()
{
if(isempty())
cout<<"\n queue is empty........";
else
cout<<"\n the deleted element of the queue is :"<<queue[front++];
}
template<class T>
void Queue<T>::display()
{
if(isempty())
cout<<"\n queue is empty.........";
else
{
cout<<"\n queue elements are :";
for(int i=front;i<=rear;i++)
{
cout<<"\t"<<queue[i];
}
}
}
int main()
{
int ch;
Queue<int> q(10);
do
{
cout<<"\n 1.insertion \n 2.deletion \n 3.front \n 4.rear \n 5.display \n 6.exit \n";
cout<<"enter ur choice:";
cin>>ch;
switch(ch)
{
case 1:
q.insertion();
break;
case 2:
q.deletion();
break;
case 3:
q._front();
break;
case 4:
q._rear();
break;
case 5:
q.display();
break;
case 6:
_exit(0);
}
}while(ch<=6);
_getch();
return 0;
}
No comments:
Post a Comment