From 5bfb95bb05cc159760ac3f3cc41f31189de93361 Mon Sep 17 00:00:00 2001 From: superprab <72614618+superprab@users.noreply.github.com> Date: Thu, 15 Oct 2020 00:56:36 +0530 Subject: [PATCH] Create circular_queue.cpp --- queue/circular_queue.cpp | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 queue/circular_queue.cpp diff --git a/queue/circular_queue.cpp b/queue/circular_queue.cpp new file mode 100644 index 00000000..fa52cf9d --- /dev/null +++ b/queue/circular_queue.cpp @@ -0,0 +1,97 @@ +#include +using namespace std; + +int cqueue[5]; +int front = -1, rear = -1, n=5; + +void insertCQ(int val) { + if ((front == 0 && rear == n-1) || (front == rear+1)) { + cout<<"Queue Overflow \n"; + return; + } + if (front == -1) { + front = 0; + rear = 0; + } else { + if (rear == n - 1) + rear = 0; + else + rear = rear + 1; + } + cqueue[rear] = val ; +} +void deleteCQ() { + if (front == -1) { + cout<<"Queue Underflow\n"; + return ; + } + cout<<"Element deleted from queue is : "<>ch; + switch(ch) { + case 1: + cout<<"Input for insertion: "<>val; + insertCQ(val); + break; + + case 2: + deleteCQ(); + break; + + case 3: + displayCQ(); + break; + + case 4: + cout<<"Exit\n"; + break; + default: cout<<"Incorrect!\n"; + } + } while(ch != 4); + return 0; +}