Check for Balanced Parentheses using Stack?

Answer Posted / hrpynux@gmail.com

If the current character is a starting bracket ('(' or '{' or '[') then push it to stack. If the current character is a closing bracket (')' or '}' or ']') then pop from stack and if the popped character is the matching starting bracket then fine else brackets are not balanced.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a singleton class c++?

630


What is purpose of new operator?

684


What is ios :: in in c++?

735


Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be

1048


What is abstract class in c++?

685






How would you use the functions randomize() and random()?

728


What is tellg () in c++?

833


Do vectors start at 0?

669


Define basic type of variable used for a different condition in C++?

757


What is the difference between the compiler and the preprocessor?

720


Why is polymorphism useful?

669


Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?

728


What is time h in c++?

688


Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;

1592


What is the difference between an enumeration and a set of pre-processor # defines?

951