are stored in the LIFO (Last In First Out) principle where the last element inserted would be the first element to be deleted. A real-world stacks, for example − a pack of cards or a pile of plates, etc.
A stack allows all data operations at one end only. At any given time, we can only access the top element of a stack. Stack uses pointers that always point to the topmost element within the stack, hence called as the top pointer.
stack ADT include: push(), pop(), peek(), isFull(), isEmpty(),display(). Working of Stack Data Structure The operations work as follows: A pointer called TOP is used to keep track of the top element in the stack. When initializing the stack, we set its value to -1 so that we can check if the stack is empty by comparing TOP == -1. On pushing an element, we increase the value of TOP and place the new element in the position pointed to by TOP. On popping an element, we return the element pointed to by TOP and reduce its value. Before pushing, we check if the stack is already full Before popping, we check if the stack is already empty
an operation retrieves the topmost element within the stack, without deleting it. This operation is used to check the status of the stack with the help of the top pointer.