Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- namespace lab1{
- class Queue{
- public:
- Queue(int size) : length(size), arr(new int[size]), begin(0), count(0), end(-1){ }
- ~Queue(){ delete []arr;}
- void push(int el){
- if(isFull())
- throw runtime_error("going beyond the boundaries of the array");
- ++end%=length;
- arr[end] = el;
- count++;
- }
- void pop(){
- int first = arr[begin];
- if(!isEmpty()){
- ++begin%=length;
- count--;
- } else {
- throw runtime_error("going beyond the boundaries of the array");
- }
- }
- int front(){
- return arr[begin];
- }
- bool isEmpty(){ return size() > 0; }
- bool isFull() { return size() == count; }
- int size() { return length; }
- private:
- int *arr;
- int length;
- int begin;
- int end;
- int count;
- };
- }
- #ifndef UNTITLED1_LAB1_H
- #define UNTITLED1_LAB1_H
- #endif //UNTITLED1_LAB1_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement