In: Computer Science
How do you implement stack by using linked list? No code just explain it.
STACK
Stack follows LIFO or Last In First Out
The Top pointer performs push and pop operation. The Top pointer points to the topmost element.
Pop operation is only performed on the topmost element.
LINKED LIST
A linked list has a collection of nodes connected through addresses.
A linked list has a head pointer pointing to the first node
How do you implement stack by using a linked list?
We will modify the working of the linked list. We will create another pointer in the linked list that will work as a TOP pointer.
A Stack looks like this
This is how a linked list is used to implement stack
Push in Linked list
We will create a new node and insert a new element in it.
Pop in Linked list
We will update the Top pointer and delete the last node.
Please don't forget to give a positive rating to the answer. Your rating motivates experts to help other students also. Thank you :)