data structures using output *****main menu**** push pop peek display exit enter your option enter the number to be pushed on stack linked representation of stacks we have seen how stack is created using an array this technique of creating stack is easybut the drawback is that the array must be declared to have some fixed size in case the stack is very small one or its maximum size is known in advancethen the array implementation of the stack gives an efficient implementation but if the array size cannot be determined in advancethen the other alternativei linked representationis used the storage requirement of linked representation of the stack with elements is ( )and the typical time requirement for the operations is ( in linked stackevery node has two parts--one that stores data and another that stores the address of the next node the start pointer of the linked list is used as top all insertions and deletions are done at the node pointed by top if top nullthen it indicates that the stack is empty the linked representation of stack is shown in fig top figure linked stack operations on linked stack linked stack supports all the three stack operationsthat ispushpopand peek push operation the push operation is used to insert an element into the stack the new element is added at the topmost position of the stack consider the linked stack shown in fig top figure linked stack to insert an element with value we first check if top=null if this is the casethen we allocate memory for new nodestore the value in its data part and null in its next part the new node will then be called top howeverif top!=nullthen we insert the new node at the beginning of the linked stack and name this new node as top thusthe updated stack becomes as shown in fig top figure linked stack after inserting new node figure shows the algorithm to push an element into linked stack in step memory is allocated for the new node in step the data part of the new node is initialized with the value to be stored in the node in step we check if the new node is the first node of the linked list this