Home Page class 12 @ Python

CBSE Class 12 : Data Structures

Introduction to Data Structures

CBSE Class 12 : Searching

Creation And Traversal
What is Searching?
Linear/Sequential Search
Binary Search
Insertion Of Element
Deletion Of Element

CBSE Class 12 : Sorting

What is sorting?
Bubble Sort
Selection Sort
Insertion Sort

CBSE Class 12 : Stacks

Stacks
Applications of Stacks
Implementation of Stacks

CBSE Class 12 : Queues

Queues
Applications Of Queues
Implementation of Queues

Class 12 Data Structures | Queues

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.

 

Python : Queue Implementation

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.

Python : Queue implementation

(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.

Python : Queue Implementation