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
- 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
- QuickSort on Doubly Linked List
- Reverse a Doubly Linked List
- Reverse a Doubly Linked List | Set-2
- Sort the biotonic doubly linked list | Set-2
- Delete all the even nodes from a Doubly Linked List
- Delete all occurrences of a given key in a doubly linked list
- Bubble Sort On Doubly Linked List
- Sort the biotonic doubly linked list
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Implementation of Deque using doubly linked list
- Doubly Circular Linked List | Set 2 (Deletion)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.