

Suppose tail is at the last element of the queue and there are empty blocks before head as shown in the picture given below. To insert any element, we add that element at tail and increase the tail by one to point to the next element of the array. head will always point to the oldest element which was added and tail will point where the new element is going to be added. We will maintain two pointers - tail and head to represent a queue.

Queues are used in a lot of applications, few of them are:
JAVA QUEUE TO ARRAY FULL
IsFull → It is used to check whether the queue is full or not.įront → It is similar to the top operation of a stack i.e., it returns the front element of the queue (but don’t delete it).īefore moving forward to code up these operations, let’s discuss the applications of a queue. IsEmpty → It is used to check whether the queue has any element or not. As stated earlier, any new item enters at the tail of the queue, so Enqueue adds an item to the tail of a queue.ĭequeue → It is similar to the pop operation of stack i.e., it returns and deletes the front element from the queue. But let’s first discuss the operations which are done on a queue.Įnqueue → Enqueue is an operation which adds an element to the queue. Similar to the stack, we will implement the queue using a linked list as well as with an array. Similar to a queue of day to day life, in Computer Science also, a new element enters a queue at the last (tail of the queue) and removal of an element occurs from the front (head of the queue). For example, a new person enters a queue at the last and the person who is at the front (who must have entered the queue at first) will be served first. It is equivalent to the queues in our general life. A queue follows FIFO (First-in, First out) policy. Similar to stacks, a queue is also an Abstract Data Type or ADT.
