Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions