Queues are partially defined by the operations you can make on them, such as enqueueing and dequeueing items, and peeking at the frontmost item. Discover the method names you can use for these operations as you stub out the queue class using Python.
- [Instructor] Let's stub out our queue class…and its methods.…We can call our class just queue, and we talked earlier…about how we're going to represent our queue as a list.…So in our init method,…we can do again like we did…for stacks, self dot items equals an empty list.…Now, our basic functionality is we need to get things…into and out of our queue, and the words that we use…for that are enqueue for adding and dequeue for removing.…
So first we can stub out the enqueue method,…and we will have to pass in as a parameter the item…that we want to add to our queue, and we'll just write pass…here for now, and then we can move on to the dequeue method.…And we don't need to pass in an item here because remember,…we're always going to be popping off the end of the list…which automatically takes the last item of the list for us.…In addition to the basic functionality of enqueueing…and dequeueing, we may also want to know what is…the next item in the queue that's going to be removed,…and we call that peek, and we'll just pass that for now.…
- 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.