#include<iostream>
using namespace std;
template<class T>
class queue
{
T q[10];
int r,f,max;
public:
queue()
{
max=5;
r=-1;
f=0;
}
void insert_rear();
void delete_front();
void display();
};
template<class T>
void queue<T>::insert_rear()
{
T item;
if(r==max-1)
cout<<"\nqueue is full\n";
else
{
cout<<"\nenter item\t";cin>>item;
q[++r]=item;
}
}
template<class T>
void queue<T>::delete_front()
{
if(f>r)
cout<<"\nquee is empty\n";
else
{
cout<<"\nitem deleted="<<q[f];
f++;
}
}
template<class T>
void queue<T>:: display()
{
if(f>r)
cout<<"\nqueue is empty\n";
else
{
cout<<"contents\n";
for(int i=f;i<=r;i++)
cout<<q[i]<<"\t";
}
}
int main()
{
queue <int>q1;
queue <double>q2;
int ch;
system("clear");
for(;;)
{
label:
cout<<"1.queue for integer\n2.quee for double\nenter choice\t";
cin>>ch;
switch(ch)
{
case 1:
for(;;)
{
cout<<"\n\n\n1.insert at rear\n2.delete at front\n3.display\nenter choice:\t";
cin>>ch;
switch(ch)
{
case 1:
q1.insert_rear();
break;
case 2:
q1.delete_front();
break;
case 3:
q1.display();
break;
default:
goto label;
}
}
break;
case 2:
for(;;)
{
cout<<"\n\n\n1.insert at rear\n2.delete at front\n3.display\nenter choice:\t";
cin>>ch;
switch(ch)
{
case 1:
q2.insert_rear();
break;
case 2:
q2.delete_front();
break;
case 3:
q2.display();
break;
default:
goto label;
}
}
break;
default:
exit(0);
}
}
}
using namespace std;
template<class T>
class queue
{
T q[10];
int r,f,max;
public:
queue()
{
max=5;
r=-1;
f=0;
}
void insert_rear();
void delete_front();
void display();
};
template<class T>
void queue<T>::insert_rear()
{
T item;
if(r==max-1)
cout<<"\nqueue is full\n";
else
{
cout<<"\nenter item\t";cin>>item;
q[++r]=item;
}
}
template<class T>
void queue<T>::delete_front()
{
if(f>r)
cout<<"\nquee is empty\n";
else
{
cout<<"\nitem deleted="<<q[f];
f++;
}
}
template<class T>
void queue<T>:: display()
{
if(f>r)
cout<<"\nqueue is empty\n";
else
{
cout<<"contents\n";
for(int i=f;i<=r;i++)
cout<<q[i]<<"\t";
}
}
int main()
{
queue <int>q1;
queue <double>q2;
int ch;
system("clear");
for(;;)
{
label:
cout<<"1.queue for integer\n2.quee for double\nenter choice\t";
cin>>ch;
switch(ch)
{
case 1:
for(;;)
{
cout<<"\n\n\n1.insert at rear\n2.delete at front\n3.display\nenter choice:\t";
cin>>ch;
switch(ch)
{
case 1:
q1.insert_rear();
break;
case 2:
q1.delete_front();
break;
case 3:
q1.display();
break;
default:
goto label;
}
}
break;
case 2:
for(;;)
{
cout<<"\n\n\n1.insert at rear\n2.delete at front\n3.display\nenter choice:\t";
cin>>ch;
switch(ch)
{
case 1:
q2.insert_rear();
break;
case 2:
q2.delete_front();
break;
case 3:
q2.display();
break;
default:
goto label;
}
}
break;
default:
exit(0);
}
}
}
No comments:
Post a Comment