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

Stack Implementation with Linked Lists

The document outlines the implementation of a stack using linked lists, specifically detailing the pseudocode for the Push and Pop operations. The Push operation involves allocating memory for a new node and adjusting pointers based on whether the stack is empty. The Pop operation checks for underflow, updates the top pointer, and frees the memory of the popped node.

Uploaded by

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

Stack Implementation with Linked Lists

The document outlines the implementation of a stack using linked lists, specifically detailing the pseudocode for the Push and Pop operations. The Push operation involves allocating memory for a new node and adjusting pointers based on whether the stack is empty. The Pop operation checks for underflow, updates the top pointer, and frees the memory of the popped node.

Uploaded by

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

SRM INSTITUTE OF SCIENCE

 AND TECHNOLOGY,
 Kattankulathur

School of Computing
21CSC201J – Data Structures and Algorithms

Topic: Stack Implementation Using Linked Lists


Activity: Fill in the Missing Pseudocode

Consider that a stack is implemented using a Linked List (Pointer


Implementation). Fill the missing Pseudocode for Push and Pop operation.
The TOP pointer points to top of Satck.

Push Operation - Algorithm to insert an element VAL in a stack


Step 1: Allocate MEMORY for the new node and name it as NEW_NODE
Step 2: SET NEW_NODE → DATA= VAL
Step 3: IF TOP = NULL
SET NEW_NODE → NEXT = NULL
SET TOP =NEW_NODE
ELSE
SET NEW_NODE → NEXT= TOP
SET TOP= NEW_NODE
[END OF IF]
Step 4: END

Pop Operation - Algorithm to delete an element from a stack


Step 1: IF TOP = NULL
PRINT UNDERFLOW
Goto Step 5
[END OF IF]
Step 2: SET PTR = TOP
Step 3: SET TOP = TOP → NEXT
Step 4: FREE PTR
Step 5: END

You might also like