![]() ![]() The linked list will be:įor the second element, the top will be incremented again by 1 and the same process will be followed. The stack will be:įor implementing this using a linked list, first, one node is to be created and the head pointer will point to that node. Before inserting the ‘top’ will be incremented by 1. Now, suppose the first element to be inserted into the stack is 10. ![]() Let the stack can contain a maximum of 3 elements.Īs the stack is implemented here using a linked list, first the head pointer is set to NULL as there is no element in the stack. Similarly, when the stack is emptyand someone is trying to delete an element from the stack then this condition is known as stack underflow. When the stack is fulland someone is trying to insert an element into the stack then this condition is known as stack overflow. First, the maximum number of elements of the stack is taken to check the boundary conditions - overflow or underflow. An array is also a linear data structure. Here, the array is used to implement the stack data structure. The insertion of any element into the stack is called ‘ push ’ and the deletion of an element is called ‘ pop ’. # The bottom-most plate which has been kept first will remain there and will be taken out at the last. which is put on the stack at last) will be taken first. The plate which is placed at the top (i.e. # The stack of plates in the kitchen can be a very simple and common example of a stack data structure. There are various real-life examples of the stack. # The element that is inserted at the last will be deleted at the first. Generally, the stack uses the LIFO approach i.e. It is a linear data structure and has a particular order of performing the operations. ![]()
0 Comments
Leave a Reply. |