Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. // !!!
  7. // Write a function Validate that will validate the 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. bool Validate(string expression)
  17. {
  18. return false;
  19. }
  20.  
  21. void Assert(bool cond, string message)
  22. {
  23. if (!cond) {
  24. printf(message.c_str());
  25. printf("\n");
  26. }
  27. }
  28.  
  29. int main2()
  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.  
  37. Assert(Validate("(){{[[(())]]}}") == true, "The expression is balanced, must be valid");
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement