Stack

Stack
- Stack is a data structure that stores data objects or items on top of each other.
- The last item to go inside the stack is placed at the top of the stack and is accessed first.
- To access the item below the top of the stack, the topmost item has to be removed before the item below it can be accessed.
- Thus, the stack follows the convention LIFO i.e Last In First Out.

Operations supported by stack
- Stack supports push, pop and top operations. Stack
ย ย ย ย ย  - Push ( item ) : Adds an item on top of the stack
ย ย ย ย ย  - Pop ( ) : Removes an item at top of the stack.
ย ย ย ย ย  - Top ( ) / Peek ( ) : Returns a copy of an item on top of the stack.

Applications of stack
– To evaluate an infix expession.
– An executable manages the storage required by its functions using a stack. Each time a function gets called, the stack grows. Each time a function returns the stack shrinks.



Copyright (c) 2019-2024, Algotree.org.
All rights reserved.