Signup/Sign In
LAST UPDATED: FEBRUARY 25, 2020

Implementing Queue in Python

    Queue is a simple data structure that works on the simple principle of "First in First out" just like an ordinary queue at a coffee shop or ticket counters etc, where the first one to enter the queue gets served first.

    In a queue, a new element is added from the rear, and existing elements are removed from the front.

    As you can see in the diagram above, new elements are added from the back, and this function of adding a new element to the queue is called Enqueue. And elements are removed from the front, which is called Dequeue.

    To learn more about how a queue works, chekout: Queue Data Structure

    Hence, to create a simple queue data structure, we need to provide it with the following functions:

    1. enqueue: To add a new data element at the rear of the queue.

    2. dequeue: To remove an element from the front of the queue.

    3. isEmpty: To return True if the queue is empty, else return False.

    4. size: To check the size of the queue, in other words, count the number of elements in the queue and return it.

    5. show: To print all the queue elements.

    We will be using Python List for implementing queue data structure.

    NOTE: We can also use the dequeue library to implement Queue in python and we can also use arrays.

    Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS