Example 59: Implementation of a Stack of Integers

Learn how to make a stack using arrays.

Problem

Write a program to implement a stack data structure.

Stack is a LIFO (Last In First Out) list in which addition and deletion occur at the same end.

How does Stack work?

Function What it does
push(value) Inserts an element at the top
pop() Removes an element from the top and returns it

Illustration

Get hands-on with 1400+ tech skills courses.