Question: C++ Programming ONLY CheckBalancedParentheses (Super Popular Interview Question) You are given a string that contains parentheses ( and ). Determine if the given string is

C++ Programming ONLY

CheckBalancedParentheses (Super Popular Interview Question)

You are given a string that contains parentheses ( and ). Determine if the given string is balanced.

Balanced parentheses means that each opening symbol has a corresponding closing symbol and the pairs of parentheses are properly nested. Consider the following correctly balanced strings of parentheses:

These are also the test cases :

TestTrue1: ()

TestTrue2: (())

TestTrue3: (()()()())

TestTrue4: (((())))

TestTrue5: (()((())()))

Compare those with the following, which are NOT balanced:

TestFalse1: (

TestFalse2: )

TestFalse3: ((((((())

TestFalse4: ()))

TestFalse5: (()()(()

Guidelines

Do not mess with the function declaration

Only code within the CheckBalancedParentheses function

To test your code run make CheckBalancedParenthesesTest.

Part 2: CheckBalancedAll

Now the string can include other characters: brackets [ ] and curly braces { }. A ( can only balance with ), a [ can only balance with ], and a { can only balance with }. Your job is to make your code from the previous problem to work with this extended use case.

These are cases where it is balanced:

These are also the test cases :

TestTrue1: [()]{}{[()()]()}

TestTrue2: {[()]}

TestTrue3: {{}[][()]}

Compare those with the following, which are NOT balanced:

TestFalse1: [(])

TestFalse2: (}{}][])

TestFalse3: []({)

Guidelines

Do not mess with the function declaration

Only code within the CheckBalancedAll function

To test your code run make CheckBalancedAllTest.

HERE IS HEADER FILE:

#ifndef CHECKBALANCED_H #define CHECKBALANCED_H

#include

bool CheckBalancedParentheses(std::string input);

bool CheckBalancedAll(std::string input);

#endif

HERE IS CPP FILE:

#include "CheckBalanced.h" #include

using namespace std;

bool CheckBalancedParentheses(std::string input) { stack stk; //Finish The Function only write here

return true; }

bool CheckBalancedAll(std::string input) { stack stk; //Finish The Function, only write here

return true; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!