You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Stack.md
+21-2Lines changed: 21 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,24 @@
1
1
# Stack
2
2
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
4
24
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