Advertisement
dimon-torchila

Untitled

Dec 15th, 2022
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. namespace lab1{
  6.     class Queue{
  7.     public:
  8.         Queue(int size) : length(size), arr(new int[size]), begin(0), count(0), end(-1){ }
  9.         ~Queue(){ delete []arr;}
  10.         void push(int el){
  11.             if(isFull())
  12.                 throw runtime_error("going beyond the boundaries of the array");
  13.             ++end%=length;
  14.             arr[end] = el;
  15.             count++;
  16.         }
  17.         void pop(){
  18.             int first = arr[begin];
  19.             if(!isEmpty()){
  20.                 ++begin%=length;
  21.                 count--;
  22.             } else {
  23.                 throw runtime_error("going beyond the boundaries of the array");
  24.             }
  25.         }
  26.         int front(){
  27.             return arr[begin];
  28.         }
  29.         bool isEmpty(){ return size() > 0; }
  30.         bool isFull() { return size() == count; }
  31.         int size() { return length; }
  32.  
  33.     private:
  34.         int *arr;
  35.         int length;
  36.         int begin;
  37.         int end;
  38.         int count;
  39.     };
  40. }
  41.  
  42. #ifndef UNTITLED1_LAB1_H
  43. #define UNTITLED1_LAB1_H
  44.  
  45. #endif //UNTITLED1_LAB1_H
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement