Queue – Data Structure

Queue - Data Structure

Welcome Learners. In this post Queue – Data Structure you will learn about the data structure queue and also how to deal with it. You will also learn what operations are related to queue. You can refer to my previous posts Stack – Data Structure if needed.

Queue – Data Structure introduction

It is linear data structure. Unlike stack queue has two ends. One is front end and the other is rear end. We use front end for deletion and rear end for insertion. These two ends are maintained use two different pointers. The pointers are Front pointer and Rear pointer.

As shown in the above diagram, you can generally imagine queue horizontally. The two ends of the queue are accessible. At the beginning when there is only one element in the queue, front and rear will be at the same position. But as you proceed with the insertion rear end moves right. When you proceed with the deletion front end moves right.

Operations of Queue

There are basically two operations of queue as well. As we know insertion and deletion happens on different ends. The two operations are Enqueue and Dequeue. This is similar to the push and pop operations of stacks. Enqueue operation is to insert element into the queue. It uses rear pointer. Dequeue operation is to delete element from the queue which proceeds through front pointer. Hence it is FIFO- First in First Out.

Additionally queue also has the same three operations as stack i.e.peek, isEmpty and isFull. You use Peek to know the front element of the queue. There difference between dequeue and peek is, dequeue removes the element and returns it, but peek returns it without deleting it. And you can use isFull method to check if the queue is full and similarly isEmpty to check if the queue is empty.