Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"stdafx.h"
- #include<string>
- using namespace std;
- // !!!
- // Write a functionValidatethat willvalidatethe brackets balance.
- // A bracket is considered to be any one of the following characters: (){}[].
- // Two brackets are considered to be a matched pair if the an opening bracket (, [, {
- // occurs to the left of a closing bracket ), ], } of the exact same type.
- // There are three types of matched pairs of brackets: [], {}, and ().
- // A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
- // For example, {[(])} is not balanced because the contents in between { and } are not balanced.
- // Function must return true if the brackets a balanced and false, if not.
- boolValidate(stringexpression)
- {
- returnfalse;
- }
- voidAssert(boolcond,stringmessage)
- {
- if(!cond) {
- printf(message.c_str());
- printf("\n");
- }
- }
- intmain2()
- {
- Assert(Validate("{") ==false,"Open bracket has not closing bracket, must not be valid");
- Assert(Validate("{[(])}") ==false,"The expression is not balanced, must not be valid");
- Assert(Validate("") ==true,"Empty expression must be valid");
- Assert(Validate("[()]") ==true,"The expression is balanced, must be valid");
- Assert(Validate("{{[[(())]]}}") ==true,"The expression is balanced, must be valid");
- return0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement