0% found this document useful (0 votes)
4 views1 page

Stack Implementation with Linked List

Uploaded by

amiscellaneous35
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Stack Implementation with Linked List

Uploaded by

amiscellaneous35
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack Implementation Using Linked List A stack works on the LIFO (Last In First

Out) principle. When using a linked list, the TOP pointer always refers to the first
node.

TOP

+-------+ +-------+ +-------+
| 40 | ---> | 30 | ---> | 20 |
+-------+ +-------+ +-------+

PUSH Operation Steps: 1. Create a new node. 2. Set newnode->next = TOP. 3.


Update TOP = newnode. After PUSH(50):

TOP

+-------+ +-------+ +-------+ +-------+
| 50 | ---> | 40 | ---> | 30 | ---> | 20 |
+-------+ +-------+ +-------+ +-------+

POP Operation Steps: 1. temp = TOP. 2. TOP = TOP->next. 3. Free temp. After
POP():

TOP

+-------+ +-------+ +-------+
| 40 | ---> | 30 | ---> | 20 |
+-------+ +-------+ +-------+

You might also like