From the course: Python Data Structures and Algorithms

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Build a queue class in Python

Build a queue class in Python

- We are now going to implement a queue class in Python. This is chapter five two so I'm going to open that folder. You would want to work on the start version of that folder. and then I'm going to open up q_ll.py. Now the reason we've called it that rather than just q.py, is because there's an existing module in Python called queue, and quite a common and hard to debug error that you might come across is if you name your own module. The same as something that already exists, then you would actually override that module and all the methods you expect to find won't work. Okay so one way to avoid that is to, just rename it to something a little bit different from the existing module. So here q_llq intel learning. So that's the folder were in so let's make a start. Now it is possible to use a list for a queue just as we did for our stack. However lists are not very efficient for this purpose. While appends and pops from the end of the list are fast doing inserts or pops from the…

Contents