Balanced Parenthesis using Stack

preview_player
Показать описание
This video describes how to implement an application of Stack - Balanced Parentheses

The following links are for reference:

Рекомендации по теме
Комментарии
Автор

Thanks in advance, now I am going to watch your video..

mukulanand
Автор

why do we return st.pop() as an argument of isMatchingPair function?

edgarcalochcampos
Автор

This is more clear and better way.
package com.rohit.demo;

import java.util.ArrayDeque;
import java.util.Deque;

public class Balanced {

public static boolean balanced(String exp) {

Deque<Character> stack = new ArrayDeque<>();

for (int i = 0; i < exp.length(); i++) {
char x = exp.charAt(i);

if (x == '(' || x == '{' || x == '[') {
stack.push(x);
continue;
}
if(stack.isEmpty())
return false;
stack.pop();
}
if (stack.isEmpty())
return true;
return false;
}

public static void main(String args[]) {
String expr = "))(({}{";

}
}

RohitChaurasiyalisten
Автор

Plzzz do answer my question . that isMachingPare merhode is made by you ou it is predifend. if it is predefined then in which package . cuz I cant find it in Java.util package .

neerajtadhiyal
Автор

Mam kamal ka ap ny samjhaya hai❤❤❤❤❤❤❤❤❤❤

BeTheOnex
Автор

You have tried your best but your explanation is not good one matching pair(st.pop().exp[i] what??

subashchandrapakhrin
Автор

Mam make more videos on data structures plz

BeTheOnex
Автор

Everyone on youtube is literally explaining the procedure but very few of them focuses on explaining the code unfortunately according to me you are not one of them, you video ws not worth watching

ManalShyhzad
Автор

7th line it should be (!st.empty()) i guess, as when the stack becomes empty it should return true, whereas here its false

vaishakhsz