Python|Queues Data Structures

Queue

The queue is an ordered collection of elements/items from which elements may be deleted from one end called the “FRONT” of the queue and into which the elements may be inserted from another end called the “REAR” of the queue.

Queue follows the policy of FIFO ( First in first out) i.e. the element which is added first will be the first to be deleted/processed.

The above-given Figure: 1 represents a queue consisting of 4 (four) elements/nodes A, B, C, and D. Node “A” represents the front of the queue and node “D” represents the rear of the queue.

Operations

(i). Addition of element

Whenever an element is added in the queue it is always added from the rear of the queue, and after the addition of element, the newly added node becomes the rear of the queue.

After addition of elements in the queue represented by fig 1, the queue will look like as given below.

(ii). Deletion of element
Whenever an element is deleted from the queue it is always deleted from the front of the queue, and after its deletion the next node in sequence becomes the front of the queue.

Considering the queue represented by fig 1 whenever an element is deleted it will be the node “A” and after its deletion next node “B” will become the front of the queue.

Visitor Counter

0142236