Deques are partially defined by the operations you can make on them, such as adding items to the front and rear, removing items from the front and rear, and checking the deque's size. Discover the method names you can use for these operations as you stub out the deque class using Python.
- [Instructor] Let's stub out the code for our deque class.…So we'll define our class and give it the name Deque…and we talked earlier about how we'll use a list…behind the scenes to represent the deque,…so lets create our init method…and within our init method, we will create an items variable…and initialize that to an empty list.…And now we need to get in to the basic functionality…of the deque, which is adding items to it…and removing items from it.…
Now remember, with a deque you can add to either side…and remove from either side.…So for each of those methods,…we're going to have to specify the location of the deque…that we want to be adding or removing from.…So lets start with add_front…and for this we'll pass in self…and the item that we want to add to the deque.…And we'll just pass for now.…And next, let's add the add_rear method.…Again, we'll need to pass in that item, that we want to add.…
And we'll do something very similar for the removal methods.…We'll do remove_front and remove_rear.…And notice here again, that we don't need to specify…
- Abstract types and data structures
- Stacks as a linear abstract data type
- Creating the Stack class and its methods
- Adding items to the top and bottom of a stack
- Creating the Queue class and its methods
- Manipulating items in a queue
- Creating the Dequeue class and its methods
- Adding and removing items from a dequeue
Skill Level Advanced
Learning the Python 3 Standard Librarywith Kathryn Hodge2h 9m Intermediate
What you should know1m 26s
1. Abstract Data Types and Data Structures
2. The Stack
3. The Queue
4. The Deque
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.