Double-Ended Queues
Learn how to leverage the power of double-ended queues!
StartImplementing Deque in Python
Lesson 1 of 1
- 1A deque, which stands for double-ended queue, is a data structure that allows users to insert and delete items at both ends of the queue. Because we can insert and delete from both ends, a deque …
- 2Imagine we want to board (or insert) a passenger from the front door of the plane. To insert items into the front of the deque, we need to implement an add_first(item) method. This method should: …
- 3Imagine we want to board (or insert) a passenger from the rear door of the plane. To insert items into the rear of the deque, we need to implement an add_last(item) method. This method should: * …
- 4The flight has landed, and it’s time to deboard the passengers. When we remove a passenger from the front door of the plane, we must remove them from the front of the deque. To remove an item from …
- 5We can deboard the rear passengers while we deboard the front passengers thanks to the flexibility of the deque structure. When we remove a passenger from the rear door of the plane, we must remove…
- 6You may need a way to determine if the plane is empty of passengers (to ensure everyone has deboarded) or to see exactly how many passengers are on board. To do this, we can implement two methods: …
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory