Guest User

please!

a guest
Oct 22nd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class rsvQueue
  6. {
  7.     friend ostream& operator<<(ostream& os,  rsvQueue& ex);
  8. private:
  9.     int maxSize;
  10.     int *rsvArray;
  11.     int front;
  12.     int rear;
  13.     int nItems;
  14. public:
  15.  
  16.     rsvQueue(int size)
  17.     {
  18.         this->maxSize = size;
  19.         rsvArray = new int[maxSize];
  20.         front = 0;
  21.         rear = -1;
  22.         nItems = 0;
  23.     }
  24.     ~rsvQueue(){
  25.         delete[] rsvArray;
  26.     }
  27.     void push(int element)
  28.     {
  29.         if (rear == maxSize - 1)
  30.             rear = -1;
  31.         rear++;
  32.         rsvArray[rear] = element;
  33.         nItems++;
  34.     }
  35.     int pop()
  36.     {
  37.         front++;
  38.         int temp = rsvArray[front];
  39.         if (front == maxSize)
  40.             front = 0;
  41.         nItems--;
  42.         return temp;
  43.     }
  44.     int peek()
  45.     {
  46.         return rsvArray[front];
  47.     }
  48.     bool isEmpty()
  49.     {
  50.         return (nItems == 0);
  51.     }
  52.     bool isFull()
  53.     {
  54.         return (nItems == maxSize);
  55.     }
  56.     int size()
  57.     {
  58.         return nItems;
  59.     }
  60. };
  61.  
  62. ostream& operator<<(ostream& os,  rsvQueue& ex)
  63. {
  64.     while (!ex.isEmpty())
  65.     {
  66.         int n = ex.pop();
  67.         os << " " << n;
  68.     }
  69.     os << " ";
  70.  
  71.     return os;
  72. }
  73.  
  74.  
  75. int main()
  76. {
  77.  
  78.     rsvQueue rsv(15);
  79.  
  80.     rsv.push(12);
  81.     rsv.push(454);
  82.  
  83.     rsv.push(14);
  84.     rsv.push(5411);
  85.     cout << endl << rsv << endl;
  86.     system("pause");
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment