Stack
- Abstract data structure . It is higher level data structure . Because it is made using array and linked list .
It follows LIFO . Meaning if insert insert to top . If pop , Pop from top .
The data structure which follows LIFO is called stack .
Suppose we are inserting a value
10 - Top
Then 20
20 - Top
10
Then 30
30- Top
20
10
Let's Pop
20 - Top
10
Again pop
10 - Top
Again pop
NULL
In array we can remove value from any index . But we cannot do it in stack .
Let's take Linked List
10 -> 20 -> 30 -> 40
We can delete value at any position .
When we delete linked list using delete_at_tail function that time is deletion in stack .
So , The characteristic of STL -
- Delete at tail
- Insert at tail
Singly linked list delete_at_tail TC - O(N)
Doubly linked list delete_at_tail TC - O(1)
Array delete at tail TC- O(1)
Stack Operation -
-push()
-pop()
-top()
-size()
-empty()
Top comments (0)