Implement Stack Using Singly Linked List
Source: https://algorithms.tutorialhorizon.com/implement-stack-using-linked-list/
Objective:
Write an algorithm to implement Stack using Linked List.
If you do not know about then for starters its abstract data type in which follows the principle of LIFO (Last-In-First-Out) which means the data goes in last comes out first to read about in detail please read this link Stack
Approach:
Solution is quite simple, Earlier we have seen an article “Linked List Implementation“, we need to make some changes to make it work as Stack.
Stack Operations:
push() :Insert the element into linked list at the beginning and increase the size of the list. O(1) operation.
pop() :Return the element first node from the linked list and move the head pointer to the second node. Decrease the size of the list. O(1) operation.
getSize(): Return the size of linked list.
displayStack(): Print the linked list.
Solution
Algorithms@tutorialhorizon
https://algorithms.tutorialhorizon.com/implement-stack-using-linked-list/
GeeksforGeeks:
https://www.geeksforgeeks.org/implement-a-stack-using-singly-linked-list/
Reference
https://algorithms.tutorialhorizon.com/implement-stack-using-linked-list/
https://www.geeksforgeeks.org/implement-a-stack-using-singly-linked-list/
Last updated
Was this helpful?