Created
June 16, 2020 17:12
-
-
Save erming/c0305fa6991a60344b4e5bf15f4695a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _QUEUE_H | |
#define _QUEUE_H | |
#undef min | |
#undef max | |
#include <queue> | |
template <class T> | |
class Queue { | |
private: | |
std::queue<T> q; | |
int max; | |
public: | |
Queue(int max) { | |
this->max = max; | |
} | |
public: | |
void push(T &value) { | |
if (isFull()) { | |
q.pop(); | |
} | |
q.push(value); | |
} | |
T pop() { | |
T value = q.front(); | |
q.pop(); | |
return value; | |
} | |
int size() { | |
return q.size(); | |
} | |
bool isFull() { | |
return size() == max; | |
} | |
bool isEmpty() { | |
return size() == 0; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment