codeintuition-logo

Pushing an item onto the stack


The push operation inserts a data item at the top of the stack. Insertion only happens after ensuring that we do not exceed the capacity constraint of the stack. The algorithm to push a value at the top of the stack is quite simple. Let us look at the possible cases we need to consider

1. Stack is full

Since the stack is full, we cannot add more items without removing items first. We will return false as this operation cannot be done.

Liking the course? Check our discounted plans to continue learning.