Complete Guide to Stack Data Structure

Complete Guide to Stack Data Structure

What is a Stack

A stack is a data structure which stores data in a sequential order, but only its latest element can be accessed. The element that is inserted into a stack last is the first one to be retrieved from the stack. Similar to a queue, a stack can be accessed only from one end of the data structure. However, unlike the queue, the last entered element in the stack is retrieved first. Thus, Stack follows the LIFO principle – Last In First Out (LIFO).

Applications of Stack

A stack is used in applications where we need to keep track of nested data.

  1. Function Calls
  2. Browser history
  3. Expression evaluation

For example, the stack is used to store function calls as they are nested into one another. We need to keep track of the latest function call, and process it first and then move back to the calling function.

Add Comment

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.