Learn how to implement a stack with a deque.
- [Instructor] Now we are ready to see…the stack container adaptor.…We call that a stack and the C++ STL…is only an adaptation of an underlying container.…In this case, the default underlying container…is the same deck we just saw.…And so, the stack adaptor will limit…the interface of this container.…It will only be able to push and pop on one end.…And for that reason, this demo will consist…on only one round of insertions…at the only end it is possible.…
And, we will display the content of the container…in one single round.…So what we'll do is push some elements in…and then pop them all out as we print them.…So let's get started.…Again, in line number nine, we include the stack header file…and I'll start with the same kind of code…you may have gotten familiar with by now.…We will define a stack of integers.…
I'll call it numbers too.…We'll use a temporary variable.…And we'll start pushing.…Again, negative numbers will end this round of pushing.…And we ask for the elements.…
Assign it to the variable…and push anything that's positive…
- Why the STL is important
- Containers and iterators
- Vectors and lists
- Stacks and dequeues
- Associative containers
Skill Level Advanced
1. The Standard Template Library
2. Vectors and Lists
3. Stacks, Queues, and Deques
4. Associative Containers
- 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.