|
1 | 1 | # STACK |
2 | 2 |
|
3 | | -stack is an ADT (abstract data type ) that act like list of objects but there is a diffrents. |
| 3 | +Stack is an ADT (abstract data type) that acts like a list of objects but there is a difference. |
4 | 4 |
|
5 | | -stack act is _LIFO_ (Last In First Out), it means that when we want to get an element from the stack we get the last element in the stack. |
| 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. |
6 | 6 |
|
7 | | -stack is based on two methods (functions) |
| 7 | +Stack is based on two methods (functions)- |
8 | 8 |
|
9 | 9 | ## push(element) |
10 | 10 |
|
11 | | -add "element" to the top of the stack. |
| 11 | +It adds "element" to the top of the stack. |
12 | 12 |
|
13 | | -for example: we have `1, 3, 5` in stack, then we call push(9), |
| 13 | +For example: If we have `1, 3, 5` in stack, and we call push(9), |
14 | 14 |
|
15 | | -`9` will add to last index of stack -> `1, 3, 5 , 9` |
| 15 | +`9` will be added to last index of stack -> `1, 3, 5 , 9`. |
16 | 16 |
|
17 | 17 | ## peek() or top() |
18 | 18 |
|
19 | | -return element at the top of the stack. |
| 19 | +It returns element at the top of the stack. |
20 | 20 |
|
21 | | -for example: we have `1, 3, 5` in stack, then we call peek(), |
| 21 | +For example: If we have `1, 3, 5` in stack, and we call peek(), |
22 | 22 |
|
23 | | -`5` will be returned (without removing it from the stack) |
| 23 | +`5` will be returned (without removing it from the stack). |
24 | 24 |
|
25 | 25 | ## pop() |
26 | 26 |
|
27 | | -remove the last element (i.e. top of stack) from stack. |
28 | | -for example: we have `1, 3, 5 , 9` in stack, then we call pop(), |
| 27 | +It removes the last element (i.e. top of stack) from stack. |
| 28 | + |
| 29 | +For example: If we have `1, 3, 5 , 9` in stack, and we call pop(), |
29 | 30 |
|
30 | 31 | the function will return `9` and the stack will change to `1, 3, 5`. |
0 commit comments