Stack In Data Structures | Data Structures and Algorithm | Data Structures in Urdu/Hindi

Published: 01 January 1970
on channel: Kacs Learnings
646
16

Welcome to our Data Structures Complete Course! Throughout this course, we're committed to delivering comprehensive knowledge to you. If you find our videos helpful, please subscribe to our channel and also share them with your friends and colleagues.

Kacs Learnings - website](https://kacslearnings.com/)

or any queries, feel free to reach out to us:

Connect with us on LinkedIn:
[Zeeshan Ilyas - LinkedIn](  / zeeshan-ilyas-61792913a  )

Connect with us on Facebook:
[Kacs Learnings - Facebook](  / kacslearnings  )

Connect with us on Instagram:
[Kacs Learnings - Instagram](https://www.instagram.com/kacslearnin...)

Connect with us on TikTok:
[Kacs Learnings - TikTok](https://www.tiktok.com/@kacs_learning...)

What is a stack?
A stack is a data structure of ordered items where items can be inserted and removed only at one end. It follows the Last-In/First-Out (LIFO) principle and is sometimes referred to as a pushdown store.

Applications of stacks:
1. Program execution
2. Parsing
3. Evaluating postfix expressions

Operations on a stack:
push: Place an item on the stack
peek/top: Look at the item on top of the stack without removing it
pop: Look at the item on top of the stack and remove it

Implementing a Stack:
A stack can be implemented using either an array or a linked list.

Using an array:
The bottom of the stack is at index 0
The top of the stack is at index numItems-1
push onto the stack at index numItems
pop off of the stack at index numItems-1

Using a linked list:
Store the items in the stack in a linked list
The top of the stack is the head node, and the bottom of the stack is the end of the list
push by adding to the front of the list
pop by removing from the front of the list

Example Problem:
What happens if we try to pop an item off the stack when the stack is empty?
This is called a stack underflow, and in Java, we use the java.util.EmptyStackException to handle it.

To create a stack in Java, import the java.util.stack package and use the Stack() constructor.

For further reference, you can download the PowerPoint presentation from the following link: [Data Structures PowerPoint Presentation](https://docs.google.com/presentation/...)

Connect with us on LinkedIn for updates and more information: [Zeeshan Ilyas - LinkedIn](  / zeeshan-ilyas-61792913a  )

Don't forget to subscribe for more enriching content on Data Structures by Kacs Learnings! #Subscribe #Data_Structures_by_KacsLearnings