Introduction to Stacks.

A stack is a linear data structure that follows the rule:

LIFO – Last In, First Out

Basic Stack Operations

Here are the main operations you’ll see everywhere:

  1. Push – Add an element to the top of the stack

  2. Pop – Remove the top element from the stack

  3. Peek / Top – View the top element without removing it

  4. isEmpty – Check if the stack is empty

  5. isFull – Check if the stack is full (for fixed-size stacks)

Simple Example

Push 10
Push 20
Push 30
Stack now looks like:

Top → 30
       20
       10
If you Pop, you remove 30.

You have completed 0% of the lesson
0%