By Naveen
A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off.
push and pop are the most common operations
push(item)
push(item)
is O(1)
pop()
pop()
is O(1)
There are two ways we can implement a stack:
Implementing a stack using an array
data[0]
data[numItems-1]
data[numItems]
data[numItems-1]
Implementing a stack using a linked list