Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef QUEUE_H
- #define QUEUE_H
- #include<vector>
- using namespace std;
- template <class X>
- class queue
- {
- vector<X> arr;
- int capacity;
- int front;
- int rear;
- int count;
- public:
- queue(int size = SIZE); // constructor
- void dequeue();
- void enqueue(X x);
- X Display();
- bool isEmpty();
- };
- template <class X>
- queue<X>::queue(int size)
- {
- arr = vector<X>(size);
- capacity = size;
- front = 0;
- rear = -1;
- count = 0;
- }
- template <class X>
- void queue<X>::dequeue()
- {
- if (isEmpty())
- cout << "\nQueue is empty\n";
- cout << "Removing " << arr[front] << '\n';
- front = (front + 1) % capacity;
- count--;
- }
- template <class X>
- void queue<X>::enqueue(X item)
- {
- if (isFull())
- {
- cout << "\nQueue is full\n";
- }
- cout << "Inserting " << item << '\n';
- rear = (rear + 1) % capacity;
- arr[rear] = item;
- count++;
- }
- // Utility function to return front element in the queue
- template <class X>
- X queue<X>::Display()
- {
- if (isEmpty())
- cout << "\nQueue is empty." << endl;
- else
- return arr;
- }
- template <class X>
- bool queue<X>::isEmpty()
- {
- return (size() == 0);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement