Skip to content

Commit 7f9555b

Browse files
authored
Update stack readme.md (#4678)
1 parent aaa2b26 commit 7f9555b

File tree

1 file changed

+17
-3
lines changed
  • src/main/java/com/thealgorithms/datastructures/stacks

1 file changed

+17
-3
lines changed

src/main/java/com/thealgorithms/datastructures/stacks/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# STACK
22

3-
Stack is an ADT (abstract data type) that acts like a list of objects but there is a difference.
3+
- 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.
44

5-
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.
5+
- 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.
66

7-
Stack is based on two methods (functions)-
7+
## Declaration
8+
`Stack<Obj> stack=new Stack<Obj>();`
9+
10+
# Functionalities
11+
Stack is based on two functions (methods)-
812

913
## push(element)
1014

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

3135
the function will return `9` and the stack will change to `1, 3, 5`.
36+
37+
# Real Life Applications
38+
- `Undo mechanisms:`
39+
Many software applications use stacks to implement an "undo" feature.
40+
41+
- `Browser history:`
42+
The "back" button in a web browser is implemented using a stack, allowing users to navigate through previously visited pages.
43+
44+
- `Function calls and recursion:`
45+
The computer's call stack keeps track of function calls, allowing programs to remember where to return after a function finishes execution.

0 commit comments

Comments
 (0)