Implementation

In this lesson, we'll see how to implement a stack.

We'll cover the following

Implementation

A stack can be implemented using an array or a singly linked list, we will have the same time complexity.

Array

The limitation in using an array is that the maximum size of the stack is limited.

We’ll keep the top pointer and A[0] will be the bottommost element.

The below code is pretty self-explanatory. Run the code to see the printed stack at every step.

Get hands-on with 1200+ tech skills courses.