Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main/java/com/thealgorithms/datastructures/stacks/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# STACK

Stack is an ADT (abstract data type) that acts like a list of objects but there is a difference.
- Stack is an ADT (abstract data type) that is a collection of elements where items are added and removed from the end, known as the "top" of the stack.

Stack works on the principle of _LIFO_ (Last In First Out), it means that the last item added to the stack will be the first item to be removed.
- Stack works on the principle of _LIFO_ (Last In First Out), it means that the last item added to the stack will be the first item to be removed.

Stack is based on two methods (functions)-
## Declaration
`Stack<Obj> stack=new Stack<Obj>();`

# Functionalities
Stack is based on two functions (methods)-

## push(element)

Expand All @@ -29,3 +33,13 @@ It removes the last element (i.e. top of stack) from stack.
For example: If we have `1, 3, 5 , 9` in stack, and we call pop(),

the function will return `9` and the stack will change to `1, 3, 5`.

# Real Life Applications
- `Undo mechanisms:`
Many software applications use stacks to implement an "undo" feature.

- `Browser history:`
The "back" button in a web browser is implemented using a stack, allowing users to navigate through previously visited pages.

- `Function calls and recursion:`
The computer's call stack keeps track of function calls, allowing programs to remember where to return after a function finishes execution.