Stack Using Single Linked List
Stack Using Single Linked List
500
400
300
200
100
Pop (To delete an element from the stack)
We can use the following steps to delete a
node from the stack...
Step 1 - Check whether stack is Empty (top
== NULL).
Step 2 - If it is Empty, then display "Stack is
Empty!!! Deletion is not possible!!!" and
terminate the function
Step 3 - If it is Not Empty, then define
a Node pointer 'temp' and set it to 'top'.
Step 4 - Then set 'top = top → next'.
Step 5 - Finally, delete 'temp'. (free(temp)).
TOP 50 400
TOP=NULL
500
Stack has no Elements.
List is empty
TOP 40 300
400
TOP 30 200
300
TOP 20 100
200
TOP 10 NULL
100
Display (To display elements of the stack)