A Brand Name ||Official Url :: Software UI Designer| Contents Designer | OS | W€B | Server | Programming | Computing Technology ::

Stack Implementation

Stack Implementation : Operations In C


Stack Implementation Using linked list

A structure is created which includes integer variable (int data) and a pointer to the next element.
Since it is a stack an element can be inserted from top and removed from top only as it follows the Last In First Out (LIFO) principle.
While stack can be done imply using arrays yet we do using Linked list because an alternative has to be present and secondly Linked list provides dynamic memory allocation. In the program element is pushed using a push function and removed using a pop function created separately and called using a switch case.
Whats the advantages of using a SRUCT as a Node
 
It’s better to use an object so you could make a template an make this linked list very versatile because it can accept every object type as the data for the node. It will be like:
LinkedList<anobjectclass></anobjectclass>
Advertisements