By using this site, you agree to this use. See details.
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Stack is a LIFO (Last in first out) data structure.
- pop() – adds an element in the stack.
- push() – removes an element from the stack.
- peek() – get the top element without removing it.
- isEmpty() – checks whether stack is empty or not.
- isFull() – checks whether stack is full or not.
There are 2 ways to implement a stack.
- Array-based Stack
- Linked List based Stack
- Easier to use.
- Less memory allocation because no need to track the next node.
- Fixed size – can not increase or decrease the array.
Link List based Stack
- Easily increase or decrease the Stack size.
- Requires extra memory to keep details about next node.
Original post : - http://mydevgeek.com/stack-data-strurcture/