From 9f7f820f9c1d9b86bae3f05965d3de9ef19c1a4e Mon Sep 17 00:00:00 2001 From: Imakshaysingh <116052474+Imakshaysingh@users.noreply.github.com> Date: Wed, 9 Nov 2022 19:30:43 +0530 Subject: [PATCH] Add files via upload --- implementQueue.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 implementQueue.cpp diff --git a/implementQueue.cpp b/implementQueue.cpp new file mode 100644 index 0000000..e4f8439 --- /dev/null +++ b/implementQueue.cpp @@ -0,0 +1,63 @@ +class Queue { + + int* arr; + int qfront; + int rear; + int size; + +public: + Queue() { + size = 100001; + arr = new int[size]; + qfront = 0; + rear = 0; + } + + /*----------------- Public Functions of Queue -----------------*/ + + bool isEmpty() { + if(qfront == rear) { + return true; + } + else + { + return false; + } + } + + void enqueue(int data) { + if(rear == size) + cout << "Queue is Full" << endl; + else + { + arr[rear] = data; + rear++; + } + } + + int dequeue() { + if(qfront == rear) { + return -1; + } + else + { int ans = arr[qfront]; + arr[qfront] = -1; + qfront++; + if(qfront==rear){ + qfront = 0; + rear = 0; + } + return ans; + } + } + + int front() { + if(qfront == rear) { + return -1; + } + else + { + return arr[qfront]; + } + } +}; \ No newline at end of file