Stack

In this lesson, we'll learn all about stacks.

We'll cover the following

Stack

A stack is a linear data structure where a particular order in operations is maintained i.e., FILO / LIFO (First In Last Out / Last In First Out).

The last inserted element is available first. First is at the bottom of the stack and so all the above elements must be removed to access the first inserted element.

The operations on stacks are:

  • Push: Add element on the top of the stack
  • Pop: Remove the top element from the stack
  • Peek/Top: Get the top element

Optionally, you have the isEmpty or size operations.

All operations take O(1)O(1) time.


Visualize

Get hands-on with 1200+ tech skills courses.