
Relevant output is displayed on the console.

Number of elements in the queue -> Size Tail Head. Which takes 23 seconds only when its multithreaded, but takes 45 seconds if the job is performed synchronously. The user input is taken for the operation that needs to be performed.ĭepending on the user’ choice, the operation is performed. Declare a list of elements and maximum size of the Queue. Task 1 sleeping 9 Task 2 sleeping 8 Task 3 sleeping 7 Task 4 sleeping 6 Task 5 sleeping 5 Task 6 sleeping 4 Task 7 sleeping 3 Task 8 sleeping 2 Task 9 sleeping 1 All done.

It has an ‘init’ function that is used to create an empty list.Īnother method named ‘check_empty’ that checks to see if a list is empty.Īnother method named ‘enqueue_elem’ is defined that adds elements to the empty list.Ī method named ‘dequeue_elem’ is defined, that deletes elements from the list.Īn object of the ‘Queue_struct’ class is created. The ‘Queue_struct’ class with required attributes is created. What operation would you perform ? Quit Explanation What operation would you perform ? Dequeue Queue in Python In this tutorial, we will discuss the Queues basic concepts and built-in Queue class and implement it using the Python code. Here are the basic operations that you can perform on a queue: Enqueue: Add elements to the queue. This means that, when you fetch an element from a queue, you’ll get whichever one you added before the others. What operation would you perform ? Enqueue 89 A queue is a linear data structure, that follows the First-In-First-Out (FIFO) principle. What operation would you perform ? Enqueue 56 Dequeue : It removes an item from the queue. What operation would you perform ? Enqueue 45 If the queue is full, then it is said to be an Overflow condition. Here are the basic queue operations that a FIFO queue commonly supports: Enqueue. Print('The deleted value is : ', my_queue_elem())

A queue has two ends, namely- rear and front. The queue is a linear data structure that stores data sequentially based on the First In First Out ( FIFO) manner and is also known as the First Come First Served data structure. dequeue: Removes the element from the front (left side) of the queue and returns it. Introduction Queue in Python Programming is one of the linear data structures used to store data in memory. My_input = input('What operation would you perform ? ').split() enqueue: Inserts an element at the rear (right side) of the queue. An instance of the class is created, and these methods are called using the instance and relevant output is displayed.īelow is a demonstration of the same − Example When it is required to implement a queue using Python, a queue class is created, and methods to add and delete elements are defined.
