Udemy

Learning Stack data structure [Java]

Enroll Now
  • 518 Students
  • Updated 2/2023
4.8
(08 Ratings)
CTgoodjobs selects quality courses to enhance professionals' competitiveness. By purchasing courses through links on our site, we may receive an affiliate commission.

Course Information

Registration period
Year-round Recruitment
Course Level
Study Mode
Duration
1 Hour(s) 6 Minute(s)
Language
English
Taught by
Monish Njs
Rating
4.8
(08 Ratings)

Course Overview

Learning Stack data structure [Java]

Problem solving using Stacks

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 stack

stack_name . empty() - returns true / false. if stack is empty, it returns true. if stack is not empty it retuns false

stack_name . clear() - clears the stack

stack_name . contains(value) - returns true if the value we check is there in stack or else it returns false
stack_name remove(index) - removes the value in given index

stack_name . search(value) - searches the value in 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, expressions in certain order we can use stacks.

2. When we wanted to use backspace character in keyboard or any similar sitautions, we can use stacks

3. When we want to delete or remove the last elements we can use stack.

4. When we want to backtrack to something and then again to move forward direction multiple times we can use stack.

5. We can use stack to find some peak elements (assuming the value plotted something like graph) we can use stacks



Course Content

  • 1 section(s)
  • 5 lecture(s)
  • Section 1 Working with Stacks

What You’ll Learn

  • How to use Stack Data structure, When to use Stack data strcuture, How to identify if the problem can be solved using Stack, Solving problems in stack

Skills covered in this course


Reviews

  • E
    Evon Troy Alexander
    5.0

    I really enjoyed the course. Straight forward and to the point.

  • K
    Kiran sai Barugala
    5.0

    would like to learn more about other frameworks too for java web development

  • S
    Shantanu Chatterjee
    5.0

    Nice explanation and most important questions

Start FollowingSee all

We use cookies to enhance your experience on our website. Please read and confirm your agreement to our Privacy Policy and Terms and Conditions before continue to browse our website.

Read and Agreed