Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <string>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. // !!!
  12.  
  13. // Write a function Validate that will validate the brackets balance.
  14.  
  15. // A bracket is considered to be any one of the following characters: (){}[].
  16.  
  17. // Two brackets are considered to be a matched pair if the an opening bracket (, [, {
  18.  
  19. // occurs to the left of a closing bracket ), ], } of the exact same type.
  20.  
  21. // There are three types of matched pairs of brackets: [], {}, and ().
  22.  
  23. // A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
  24.  
  25. // For example, {[(])} is not balanced because the contents in between { and } are not balanced.
  26.  
  27. // Function must return true if the brackets a balanced and false, if not.
  28.  
  29.  
  30.  
  31. bool Validate(string expression)
  32.  
  33. {
  34.  
  35. return false;
  36.  
  37. }
  38.  
  39.  
  40.  
  41. void Assert(bool cond, string message)
  42.  
  43. {
  44.  
  45. if (!cond) {
  46.  
  47. printf(message.c_str());
  48.  
  49. printf("\n");
  50.  
  51. }
  52.  
  53. }
  54.  
  55.  
  56.  
  57. int main()
  58.  
  59. {
  60.  
  61. Assert(Validate("{") == false, "Open bracket has not closing bracket, must not be valid");
  62.  
  63. Assert(Validate("{[(])}") == false, "The expression is not balanced, must not be valid");
  64.  
  65. Assert(Validate("") == true, "Empty expression must be valid");
  66.  
  67. Assert(Validate("[()]") == true, "The expression is balanced, must be valid");
  68.  
  69. Assert(Validate("{{[[(())]]}}") == true, "The expression is balanced, must be valid");
  70.  
  71. Assert(Validate("(){{[[(())]]}}") == true, "The expression is balanced, must be valid");
  72.  
  73. return 0;
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement