#include<iostream.h>
#include<conio.h>
template<class T>
class Queue
{
private:
T *que;
int size;
int front;
int rear;
public:
Queue (int max = 5); // constructor
~Queue() //destructure
{
delete[]que;
}
void addElement(const T&);
int deleteElement(T& item);
int Qfull() const
{
return rear == size;
}
int Qempty() const
{
return (front>=rear || rear==0);
}
void display(void);
}; // End of class template
template<class T>
Queue<T> :: Queue (int sz)
{
size = sz;
front = 0;
rear = 0;
que = new T[size];
}
template <class T>
int Queue <T> :: addElement (const T &element)
{
if(!Qfull())
{
que[rear] = element;
rear = rear + 1;
return 1;
}
else
return 0;
}
template<class T>
int Queue <T> :: deleteElement(T &item)
{
T item;
if (!Qempty ())
{
item = que[front];
front = front + 1;
return 1;
}
else
return 0;
}
template<class T>
void Queue <T> :: display (void)
{
if (Qempty())
{
cout<< "Empty Que" <<endl;
return;
}
cout<<endl;
cout<<"Status of the que is ";
cout<<endl;
for (int i = front; i <rear; i++)
{
cout <<que[i] <<" ";
}
cout<<endl;
}
int main()
{
Queue<int>IQ(5);
Queue<double>DQ(5);
int ival;
double dval;
cout<<endl;
cout<<"Insert Integer numbers";
cout<<endl;
while(!(IQ.Qfull()))
{
cin>>ival;
IQ.addElement(ival);
}
IQ.display();
cout<<"Queue Full";
cout<<endl;
cout<<"Elements are deleted in the order in which they are inserted";
cout<<endl;
while(!(IQ.Qempty()))
{
IQ.deleteElement(ival);
cout<<ival<<" is deleted"<<endl;
}
IQ.display();
cout<<"Now, insert double-precision numbers"<<endl;
while(!(DQ.Qfull()))
{
cin >>dval;
DQ.addElement(dval);
}
DQ.display();
cout<<"Queue full";
cout<<endl;
cout<<"Delete elements";
cout<<endl;
while (!(DQ.Qempty()))
{
DQ.deleteElement(dval);
cout<<dval<<"is deleted";
cout<<endl;
}
DQ.display();
getch();
return 0;
}; // End of main
Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement 
Corporate Services
  Web Design and development
  Web Promotion (SEO)
  Multimedia/CD Presentation
  Software development

  E.Commerce

Training@balujalabs

  Software Courses
  Hardware Courses
  Networking.Courses
  Mobile Repairing Courses
  UGC Degrees
Student Corner
 Programming & Projects
 Placement Papers
 Project Ideas
 Synopsis Ideas

  Franchise Section

 Administrator
Franchise Inquiry
 
 

This program is to create a template class Queue, with add and delete member functions. And, using this class template, a queue of integers and doubles is implemented.

 

 

 

 

 

 

 

 

 

                                                                                                                                          

1 This program illustrates the definition and declaration of a class template for accepting two numbers and finding their sum.
2 This process is to define and declare a class template for stack. A stack is a data structure in which all insertions and deletions are made at the same end called top insertions are called push operations while deletions are referred to as pop operations.
3 This program is to create a template class Queue, with add and delete member functions. And, using this class template, a queue of integers and doubles is implemented.
4 This program illustrates the static data members of class templates.

 

     
Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement