C++ Data StructuresLesson 50Free preview
C++ Stacks
This lesson is part of C++ · All levels
Summary
A stack is a container with the LIFO principle (last in, first out): the last element that enters is the first to leave. The operation is very limited and simple, i.e. push to add, pop to delete, and top to see the top element. In C++, a stack is an adapter built on top of another container, usually a deque, so it is suitable for undo, history navigation, and expression evaluation.
Key points
- The principle of stack work is LIFO: last in, first out.
- Push() add up, pop() delete up, top() read up without deleting.
- The stack does not provide an iteration or access to the element in the middle.
- Empty() and size() are used to check the contents before accessing top().
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.