Learning Stack data structure [Java]
Problem solving using Stacks
Development,Software Engineering,Data Structures
Lectures -5
Duration -1 hours
30-days Money-Back Guarantee
Get your team access to 10000+ top Tutorials Point courses anytime, anywhere.
Course Description
Stack:
Stack stores elements of the same data type.
We can insert, and remove elements in the stack in the Last In First Out policy (LIFO)
Declaration
Stack<Type> variable_name = new Stack<>();
Stack<Integer> stack = new Stack<>();
Methods used in Stack:
stack_name . push() - insert element into a stack
stack_name . peek() - checks the topmost element in the stack
stack_name . pop() - removes the topmost element in the stack
stack_name . size() - returns the number of elements in the stack
stack_name . empty() - returns true/false. if the stack is empty, it returns true. if the stack is not empty it returns false
stack_name . clear() - clears the stack
stack_name . contains(value) - returns true if the value we check is there in a stack or else it returns false
stack_name remove(index) - removes the value in the given index
stack_name . search(value) - searches the value in the stack and returns us the index of the value if present.
Iterating stack:
We can go through the stack elements in two ways.
1. Popping the elements
We can pop the stack elements one by one and go through all the elements.
2. For each loop
We can go through the stack by a for loop as below
for(String s : stack_name)
{
//Stack will be iterated from bottom to top direction in this way
}
How to identify if that problem can be solved using a stack
1. when we want to evaluate brackets, and expressions in a certain order we can use stacks.
2. When we want to use backspace characters in the keyboard or in any similar situations, we can use stacks
3. When we want to delete or remove the last elements we can use the stack.
4. When we want to backtrack to something and then again move forward direction multiple times we can use the stack.
5. We can use stack to find some peak elements (assuming the value plotted something like a graph) we can use stacks
Who this course is for:
- Developers who are learning Data structures and Algorithms
Goals
- How to use Stack Data structure
- When to use Stack data structure
- How to identify if the problem can be solved using Stack
- Solving problems in the stack
Prerequisites
Required to know basic Core Java
![Learning Stack data structure [Java] Learning Stack data structure [Java]](https://d3mxt5v3yxgcsr.cloudfront.net/courses/16816/course_16816_image.jpg)
Curriculum
Check out the detailed breakdown of what’s inside the course
Working with Stacks
5 Lectures
-
Introduction to Stacks 10:28 10:28
-
Check if Parentheses are balanced 12:48 12:48
-
Backspace string compare 10:31 10:31
-
Simplify path 13:35 13:35
-
Next greater element 19:12 19:12
Instructor Details
![Monish Njs](https://www.tutorialspoint.com/assets/profiles/623465/profile/200_4110020-1679397540.jpeg)
Monish Njs
I am a Senior Software Engineer in PayPal. I enjoy coding, especially solving problems on Leetcode. I want to share what I know by creating a course, and I'm excited to present my course on Data Structures and Algorithms in Java. I've put a lot of effort into making my courses easy to understand, explaining concepts in the simplest way I can.
Course Certificate
Use your certificate to make a career change or to advance in your current career.
![sample Tutorialspoint certificate](/market/public/assets/newDesign/img/primePacks/V-certificate.png)
Our students work
with the Best
![adobe logo](/market/public/assets/newDesign/img/adobe.png)
![adp logo](/market/public/assets/newDesign/img/adp.png)
![apple logo](/market/public/assets/newDesign/img/apple.png)
![armani logo](/market/public/assets/newDesign/img/armani.jpg)
![bosch logo](/market/public/assets/newDesign/img/bosch.png)
![capegemini logo](/market/public/assets/newDesign/img/capegemini.png)
![cisco logo](/market/public/assets/newDesign/img/cisco.png)
![hdfc bank logo](/market/public/assets/newDesign/img/hdfcbank.png)
![ibm logo](/market/public/assets/newDesign/img/ibm.png)
![intel logo](/market/public/assets/newDesign/img/intel.png)
![mastercard logo](/market/public/assets/newDesign/img/mastercard.png)
![netflix logo](/market/public/assets/newDesign/img/netflix.png)
![qualcomm logo](/market/public/assets/newDesign/img/qualcomm.png)
![samsung logo](/market/public/assets/newDesign/img/samsung.png)
![sony logo](/market/public/assets/newDesign/img/sony.png)
![unilever logo](/market/public/assets/newDesign/img/unilever.png)
![walmart logo](/market/public/assets/newDesign/img/walmart.png)
![adobe logo](/market/public/assets/newDesign/img/adobe.png)
![adp logo](/market/public/assets/newDesign/img/adp.png)
![apple logo](/market/public/assets/newDesign/img/apple.png)
![armani logo](/market/public/assets/newDesign/img/armani.jpg)
![bosch logo](/market/public/assets/newDesign/img/bosch.png)
![capegemini logo](/market/public/assets/newDesign/img/capegemini.png)
![cisco logo](/market/public/assets/newDesign/img/cisco.png)
![hdfcbank logo](/market/public/assets/newDesign/img/hdfcbank.png)
![ibm logo](/market/public/assets/newDesign/img/ibm.png)
![intel logo](/market/public/assets/newDesign/img/intel.png)
![mastercard logo](/market/public/assets/newDesign/img/mastercard.png)
![netflix logo](/market/public/assets/newDesign/img/netflix.png)
![qualcomm logo](/market/public/assets/newDesign/img/qualcomm.png)
![samsung logo](/market/public/assets/newDesign/img/samsung.png)
![sony logo](/market/public/assets/newDesign/img/sony.png)
![unilever logo](/market/public/assets/newDesign/img/unilever.png)
![walmart logo](/market/public/assets/newDesign/img/walmart.png)
Related Video Courses
View MoreAnnual Membership
Become a valued member of Tutorials Point and enjoy unlimited access to our vast library of top-rated Video Courses
Subscribe now![Annual Membership Annual Membership](/market/public/assets/newDesign/img/membership-large-small.jpg)
Online Certifications
Master prominent technologies at full length and become a valued certified professional.
Explore Now![Online Certifications Online Certifications](/market/public/assets/newDesign/img/traning-for-a-team.png)