A stacks is a simple data structure use for storing data (similar to linked list).
What is a Stack?
A stack is as order list in which insert and delete actions are at one end, it is top. The last element insert is the first one to be delete. Hence, it is calls as the Last in First out (LIFO) or First in Last out (FILO) list. In stack, the order in which the data arrives is important. A pile of plates in a cafeteria is a good example of a stack. The plates are add to the stack as they are clean and they are place on the top. When a plate, is require it is take from the top of the stack. The first plate place on the stack is the last one to be use.
Speacial names are give to the two changes that can be make to a stack. When an element is insert in a stack, the concept is call as push, and when an element is remove from the stack, the concept is call as pop. Trying to pop out an empty stack is call as underflow and trying to push an element in the full stack is call as overflow. Generally, we treat them as exceptions. As an example, consider below picture,
How stacks are used-
Consider a working day in the office . Let us assume a developers is working on a long-term project. The manager then gives the developer a new task which is more important. The developer puts the long-term project aside and begins work on the new task. The phone rings, and this is hignest priority as it must be answered immediately. The developer pushes the present task into the pending tray and answers the phone.
When the call is complete the task that was abandoned to the answer the phone is retrieve from the pending tray and work progress. To take another call, it may have to be handle in the same manner, but eventually the new task will be finished, and the developer can draw the long-term project from the pending tray and continue with that.