Stack Using Array
Stack Using Array
A stack is a linear data structure that follows the principle of Last In First Out (LIFO).
This means the last element inserted inside the stack is removed first.
1. A Stack is a linear data structure that follows the LIFO (Last-In-First-Out)
principle. Stack has one end, that is It contains only one pointer top pointer
pointing to the topmost element of the stack.
2. Whenever an element is added in the stack, it is added on the top of the stack,
and the element can be deleted only from the stack. In other words, a stack can
be defined as a container in which insertion and deletion can be done from
the one end known as the top of the stack.
3. To add it has one method Push which add it to topmost in stack O(1)
4. To add it has one method Pop which remove the topmost element in stack O(1)
push()
Adding element to top most
Big O: O(1) constant
pop()
Removing element from top
Big O: O(1) constant
peek()
Just to see the topmost element and not removing it
Big O: O(1) constant
isFull()
To check whether the Stack is full or not
Big O: O(1) constant
isEmpty()
To check whether the Stack is empty or not
Big O: O(1) constant
count()
To return the count of the stack
Big O: O(1) constant
References
Programiz.
Geeksforgeeks