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; +}