


The person to arrive first leaves first and the person to arrive last leaves last.People enter the line from one end and leave at the other end.Let's make a few observations based on this example: Here you will learn how to do it in the Pythonic way and in a language agnostic way.Ī Queue is a simple data structure concept that can be easily applied in our day to day life, like when you stand in a line to buy coffee at Starbucks. Python implementation of Queue is relatively simple when compared to other languages. These concepts are often tested in interviews and have a wide variety of applications. This tutorial will help you understand a Queue data structure and how to implement it. Basic data structure concepts like List (Click here to refresh List concepts).To learn about the Queue data structure, you should first have a good understanding of the following: In the below example we create a queue class where we insert the data and then remove the data using the in-built pop method.Last Updated: Wednesday 23 rd August 2017 Prerequisites When the above code is executed, it produces the following result − We use the in-built insert method for adding data elements.

In the below example we create a queue class where we implement the First-in-First-Out method. Their is no insertion as data elements are always added at the end of the queue. So it is a First-in-First out method.Ī queue can be implemented using python list where we can use the insert() and pop() methods to add and remove elements. The items are allowed at on end but removed form the other end. The uniqueness of queue lies in the way items are added and removed. The queue data structure aslo means the same where the data elements are arranged in a queue. We are familiar with queue in our day to day life as we wait for a service. Python Data Structure & Algorithms Useful Resources.Python Data Structure and Algorithms Tutorial.
