Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class rsvQueue
- {
- friend ostream& operator<<(ostream& os, rsvQueue& ex);
- private:
- int maxSize;
- int *rsvArray;
- int front;
- int rear;
- int nItems;
- public:
- rsvQueue(int size)
- {
- this->maxSize = size;
- rsvArray = new int[maxSize];
- front = 0;
- rear = -1;
- nItems = 0;
- }
- ~rsvQueue(){
- delete[] rsvArray;
- }
- void push(int element)
- {
- if (rear == maxSize - 1)
- rear = -1;
- rear++;
- rsvArray[rear] = element;
- nItems++;
- }
- int pop()
- {
- front++;
- int temp = rsvArray[front];
- if (front == maxSize)
- front = 0;
- nItems--;
- return temp;
- }
- int peek()
- {
- return rsvArray[front];
- }
- bool isEmpty()
- {
- return (nItems == 0);
- }
- bool isFull()
- {
- return (nItems == maxSize);
- }
- int size()
- {
- return nItems;
- }
- };
- ostream& operator<<(ostream& os, rsvQueue& ex)
- {
- while (!ex.isEmpty())
- {
- int n = ex.pop();
- os << " " << n;
- }
- os << " ";
- return os;
- }
- int main()
- {
- rsvQueue rsv(15);
- rsv.push(12);
- rsv.push(454);
- rsv.push(14);
- rsv.push(5411);
- cout << endl << rsv << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment