A stack is a collection of objects that are inserted and removed using Last in First out Principle(LIFO). User can insert elements into the stack, and can only access or remove the recently inserted object on top of the stack. The main advantage of using LinkedList over array for implementing stack is the dynamic allocation of data whereas in the array, the size of the stack is restricted and there is a chance of stack overflow error when the size of the stack is exceeded the maximum size.
1. push() : Insert the element into Stack and assign the top pointer to the element.
2. pop() : Return top element from the Stack and move the top pointer to the
second element of the Stack.
3. top() : Return the top element.
4. size() : Return the Size of the Stack.
5. isEmpty() : Return True if Stack is Empty else return False.
6. printstack() : Print all elements of the stack.
Below is the implementation of the above-mentioned stack operations using Doubly LinkedList in Python:
Stack operations using Doubly LinkedList stack elements are: 7->6->5->4-> Top element is 7 Size of the stack is 4 stack elements are: 5->4-> stack is empty: False
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Python | Queue using Doubly Linked List
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- Construct a Doubly linked linked list from 2D Matrix
- Reverse a Doubly Linked List | Set-2
- QuickSort on Doubly Linked List
- Reverse a Doubly Linked List
- Doubly Linked List Tutorial
- Rotate Doubly linked list by N nodes
- Sort a k sorted doubly linked list
- Priority Queue using doubly linked list
- Bubble Sort On Doubly Linked List
- Sort the biotonic doubly linked list
- Delete all occurrences of a given key in a doubly linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SuparnaRaut