fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class QUEUE {
  5. private:
  6. int* q;
  7. int N;
  8. int head;
  9. int tail;
  10. public:
  11. QUEUE(int maxN) {
  12. q = new int[maxN + 1];
  13. N = maxN + 1; head = N; tail = 0;
  14. }
  15. int empty() const {
  16. return head % N == tail;
  17. }
  18. void put(int item) {
  19. q[tail++] = item; tail = tail % N;
  20. }
  21. int get() {
  22. head = head % N; return q[head++];
  23. }
  24. };
  25.  
  26. int main() {
  27. int n = 5;
  28. QUEUE q(n);
  29. for (int i = 0; i < n + 1; ++i){
  30. q.put(1);
  31. }
  32. cout << q.empty() << "\n";
  33. return 0;
  34. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
1