Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include"stdafx.h"
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. // !!!
  7. // Write a functionValidatethat willvalidatethe brackets balance.
  8. // A bracket is considered to be any one of the following characters: (){}[].
  9. // Two brackets are considered to be a matched pair if the an opening bracket (, [, {
  10. // occurs to the left of a closing bracket ), ], } of the exact same type.
  11. // There are three types of matched pairs of brackets: [], {}, and ().
  12. // A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
  13. // For example, {[(])} is not balanced because the contents in between { and } are not balanced.
  14. // Function must return true if the brackets a balanced and false, if not.
  15.  
  16. boolValidate(stringexpression)
  17. {
  18. returnfalse;
  19. }
  20.  
  21. voidAssert(boolcond,stringmessage)
  22. {
  23. if(!cond) {
  24. printf(message.c_str());
  25. printf("\n");
  26. }
  27. }
  28.  
  29. intmain2()
  30. {
  31. Assert(Validate("{") ==false,"Open bracket has not closing bracket, must not be valid");
  32. Assert(Validate("{[(])}") ==false,"The expression is not balanced, must not be valid");
  33. Assert(Validate("") ==true,"Empty expression must be valid");
  34. Assert(Validate("[()]") ==true,"The expression is balanced, must be valid");
  35. Assert(Validate("{{[[(())]]}}") ==true,"The expression is balanced, must be valid");
  36. return0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement