Loading

Quipoin Menu

Learn • Practice • Grow

data-structure-with-java / Stack Introduction
tutorial

Stack Introduction

Imagine a stack of plates. You add a new plate on top, and you remove the top plate first. This is Last In, First Out (LIFO) behavior. In computer science, a stack is a linear data structure that follows LIFO principle.

A stack has two primary operations:
  • push – add an element to the top
  • pop – remove the top element
  • peek – view the top element without removing it
  • isEmpty – check if stack is empty

Stacks are used in function call management (recursion), undo/redo, expression evaluation, and backtracking.

Here's a simple stack interface in Java:


public interface Stack<T> {
void push(T item);
T pop();
T peek();
boolean isEmpty();
int size();
}
Two Minute Drill
  • Stack is a LIFO data structure.
  • Main operations: push, pop, peek, isEmpty.
  • Used in recursion, undo, expression evaluation, backtracking.
  • Can be implemented using arrays or linked lists.

Need more clarification?

Drop us an email at career@quipoinfotech.com