Skip to content

Commit b78d413

Browse files
authored
Update Stack.md
1 parent 5111642 commit b78d413

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Stack.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Stack
22

3-
A stack is a linear data structure. It follows the last in first out approach. A new item is added at the top of a stack. Both insert and deletion operation is performed from one end of the stack.
3+
A stack is a linear data structure that follows the principle of Last In First Out (LIFO). This means the last element inserted inside the stack is removed first.
4+
5+
In stacks, the insertion and deletion of elements happen only at one endpoint of it.
6+
7+
## How to understand stack practically
8+
You can think of the stack data structure as the pile of plates on top of another.
9+
10+
Here, you can:
11+
12+
* Put a new plate on top
13+
* Remove the top plate
14+
15+
And, if you want the plate at the bottom, you must first remove all the plates on top. This is exactly how the stack data structure works.
16+
17+
## Methods to implement Stack in C
18+
* **Statically**: Array implementation of stacks allows the static memory allocation of its data elements. It is important to note that in this method, the stack acquires all the features of an array.
19+
* **Dynamically**: Linked list implementation of stacks follow the dynamic memory allocation of its data elements. It is important to note that in this method, the stack inherits all the characteristics of a linked list in C.
20+
21+
## Operations performed on stack
22+
23+
### Push : Adding an element onto the stack
424

5-
There are two functions associated with stacks. Push function to add elements to the stack and pop function to remove elements from the stack.

0 commit comments

Comments
 (0)