What is a Stack?
💻 coding

What is a Stack?

1 min read 225 words
1 min read
ShareWhatsAppPost on X
  • 1A stack is a data structure where data is stored in a Last In First Out (LIFO) manner.
  • 2Main operations of a stack include 'push' to insert data and 'pop' to remove the last inserted element.
  • 3Stacks are used in various applications like balancing symbols, function calls, and managing browser history.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"A stack is a data structure where data is stored in a Last In First Out (LIFO) manner."

What is a Stack?

A stack is a simple data structure used for storing data (similar to Linked Lists). In stack the order in which the data arrives is important. The pile of plates of a cafeteria is a good example of a stack. The plates are added to the stack as they are cleaned. They are placed on the top. When a plate is required it is taken from the top of the stack. The first plate placed on the stack is the last one to be used.

A Stack is an ordered list in which insertion and deletion are done at one end, called as the top. The last element inserted is the first one to be deleted. Hence, it is called Last In First Out (LIFO) or First In Last Out (FILO) list.

Stack ADT

Main stack operations:

- void push (int data): Inserts data onto a stack.

- int pop(): Removes and returns the last inserted element from the stack.

Applications:

- Balancing of symbols

- Infix-to-postfix conversion

- Evaluation of postfix expression

- Implementing function calls (including recursion)

- Finding of spans (finding spans in stock markets)

- Page-visited history in a Web Browser (Back Buttons)

- Undo sequence in a text editor

- Matching Tags in HTML and XML

source: Data Structures and Algorithms Made Easy in Java ( By Narasimha Karumanchi )

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 8 August 2018 · 1 min read · 225 words

Part of AskGif Blog · coding

You might also like