Given a string consisting of brackets, write a program to examine whether the pairs and the orders of "{", "}", "(", ")", "[", "]" are correct (balanced). For example, the program should print true for the string [()]{}{[()()]()} and false for ()[]}.
The classic algorithm for solving this problem relies on using a stack.
1. create an instance of a stack;
2. traverse the input string;
2.1 if the current character is a starting bracket "(" or "{" or "{" then push it to the stack;
2.2 if the current is a closing bracket ")" or "}" or "]" then remove (pop) the top element from the stack; if the popped bracket is the matching starting bracket then fine else parenthesis are not balanced;
3. after completing traversal, if there are some starting brackets left in the stack, then the parenthesis are not balanced.
Sample Input:
([][])
Sample Output:
true.
Блин ребят, второй пункт, проверка на совпадающую скобочку, я не могу ничего придумать как миллион ифов сделать, дайте идею как можно обойти это