This is a preview
This playground version isn't public and is work in progress.
Introduction
Stack is a LIFO (Last in first out) data structure.
Operations
- 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.
Implementation
There are 2 ways to implement a stack.
- Array-based Stack
- Linked List based Stack
Array-based Stack
Pros:-
- Easier to use.
- Less memory allocation because no need to track the next node.
Cons:-
- Fixed size – can not increase or decrease the array.
Link List based Stack
Pros:-
- Easily increase or decrease the Stack size.
Cons:-
- Requires extra memory to keep details about next node.
Original post : - http://mydevgeek.com/stack-data-strurcture/
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content