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 are the two shift operators and what are their functions?

561


Describe the process of creation and destruction of a derived class object?

643


Difference between Abstraction and encapsulation in C++?

580


If horse and bird inherit virtual public from animal, do their constructors initialize the animal constructor? If pegasus inherits from both horse and bird, how does it initialize animal’s constructor?

640


What is a hash function c++?

554






Explain the differences between private, public and protected and give examples.

567


What do you mean by storage classes?

794


What is c++ hash?

622


What parameter does the constructor to an ofstream object take?

613


How do you write a function that can reverse a linked-list?

576


what are Operators and explain with an example?

709


What is the difference between the functions memmove() and memcpy()?

636


Who invented turbo c++?

607


Can constructor be private in c++?

607


Can we use clrscr in c++?

535