Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef QUETYPE_H_INCLUDED
- #define QUETYPE_H_INCLUDED
- template<class T>
- class QueType
- {
- public:
- QueType();
- QueType(int);
- ~QueType();
- void MakeEmpty();
- bool IsEmpty();
- bool IsFull();
- void Enqueue(T);
- void Dequeue(T &);
- T Front();
- private:
- int front;
- int rear;
- T *info;
- int maxQue;
- };
- #endif // QUETYPE_H_INCLUDED
- *************************************************************
- #include "quetype.h"
- #include <iostream>
- using namespace std;
- template<class T>
- QueType<T>::QueType()
- {
- maxQue=501;
- front = - 1;
- rear = - 1;
- info=new T[maxQue];
- }
- template<class T>
- QueType<T>::QueType(int max)
- {
- maxQue= max + 1;
- front = - 1;
- rear = - 1;
- info=new T[maxQue];
- }
- template<class T>
- QueType<T>::~QueType()
- {
- delete [] info;
- }
- template<class T>
- void QueType<T>:: MakeEmpty()
- {
- front=-1;
- rear=-1;
- }
- template<class T>
- bool QueType<T>::IsEmpty()
- {
- return (rear == front);
- }
- template<class T>
- bool QueType<T>::IsFull()
- {
- return((rear+1)%maxQue==front);
- }
- template<class T>
- void QueType<T>::Enqueue(T item)
- {
- if(IsFull())
- {
- cout<<"Queue Overflow "<<endl;
- }
- else
- {
- rear = (rear+1)%maxQue;
- info[rear]=item;
- }
- }
- template<class T>
- void QueType<T>::Dequeue(T &item)
- {
- if(IsEmpty())
- {
- cout<<"Queue is underflow"<<endl;
- }
- else
- {
- front=(front+1)%maxQue;
- item=info[front];
- }
- }
- *********************************************************************
- #include <iostream>
- #include "quetype.cpp"
- using namespace std;
- int main()
- {
- QueType <int> ob1(5),ob2;
- if(ob1.IsEmpty())
- {
- cout<< "Queue is Empty "<<endl;
- }
- else{
- cout<<"Queue is not Empty "<<endl;
- }
- int temp;
- cout << "Enter Four Numbers : ";
- for(int i=0; i<4; i++)
- {
- cin>>temp;
- ob1.Enqueue(temp);
- }
- if(ob1.IsEmpty())
- {
- cout<< "Queue is Empty"<<endl;
- }
- else
- cout<<"Queue is not Empty"<<endl;
- if(ob1.IsFull())
- {
- cout<< "Queue is Full"<<endl;
- }
- else
- {
- cout<<"Queue is not Full"<<endl;
- }
- cout << "Enter another Integer Number :";
- cin>>temp;
- ob1.Enqueue(temp);
- cout<<"Printing value"<<endl;
- for(int i=0; !ob1.IsEmpty(); i++)
- {
- ob1.Dequeue(temp);
- cout << temp << " ";
- ob2.Enqueue(temp);
- }
- for(int i=0; !ob2.IsEmpty(); i++)
- {
- ob2.Dequeue(temp);
- ob1.Enqueue(temp);
- }
- if(ob1.IsFull())
- {
- cout<< "Queue is Full"<<endl;
- }
- else
- {
- cout<<"Queue is not Full"<<endl;
- }
- ob1.Dequeue(temp);
- ob1.Dequeue(temp);
- cout<<"Printing value"<<endl;
- for(int i=0; !ob1.IsEmpty(); i++)
- {
- ob1.Dequeue(temp);
- cout << temp << " ";
- ob2.Enqueue(temp);
- }
- for(int i=0; !ob2.IsEmpty(); i++)
- {
- ob2.Dequeue(temp);
- ob1.Enqueue(temp);
- }
- ob1.Dequeue(temp);
- ob1.Dequeue(temp);
- ob1.Dequeue(temp);
- if(ob1.IsEmpty())
- {
- cout<< "Queue is Empty"<<endl;
- }
- else
- cout<<"Queue is not Empty"<<endl;
- cout << "Enter Five Numbers : ";
- for(int i=0; i<5; i++)
- {
- cin>>temp;
- ob1.Enqueue(temp);
- }
- cout<<"Reverse printing value"<<endl;
- int array[5];
- for(int i=0; !ob1.IsEmpty(); i++)
- {
- ob1.Dequeue(temp);
- array[i]=temp;
- }
- for(int i=4; i>=0; i--)
- {
- cout<< array[i]<< " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement