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 stack's capacity constraint. Unlike the array implementation, in the linked list implementation of a stack, we need to take some extra steps to maintain the head reference. Let's look at the possible cases we need to consider.

1. Stack is full

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

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