diff --git a/algorithms/data-structures/queue/Circular_queue.cpp b/algorithms/data-structures/queue/Circular_queue.cpp new file mode 100644 index 00000000..83fd8ca2 --- /dev/null +++ b/algorithms/data-structures/queue/Circular_queue.cpp @@ -0,0 +1,68 @@ +#include +using namespace std; +class MyCircularQueue +{ +public: + int cap; + deque q; + + MyCircularQueue(int k) + { + + cap = k; + } + + bool enQueue(int value) + { + + if (isFull()) + return false; + q.push_back(value); + return true; + } + + bool deQueue() + { + + if (isEmpty()) + return false; + q.pop_front(); + return true; + } + + int Front() + { + if (isEmpty()) + return -1; + + return q.front(); + } + + int Rear() + { + if (isEmpty()) + return -1; + + return q.back(); + } + + bool isEmpty() + { + return (q.size() == 0); + } + + bool isFull() + { + return (q.size() == cap); + } +}; +int main() +{ + MyCircularQueue q(5); + for (int i=1;i<=5;i++){ + q.enQueue(i); + } + + + return 0; +} \ No newline at end of file diff --git a/algorithms/data-structures/queue/Circular_queue.exe b/algorithms/data-structures/queue/Circular_queue.exe new file mode 100644 index 00000000..3541ff8a Binary files /dev/null and b/algorithms/data-structures/queue/Circular_queue.exe differ