balance bracket question in C code example
Example 1: bracket balancing c++
/*
PARENTHESE MATCHING
AUTHOR: UTKARSH SINHA
*/
bool correct_paranthesis(string str){
stack stk;
map bracket_map;
bracket_map[')'] = '(';
bracket_map['}'] = '{';
bracket_map[']'] = '[';
for(int i=0; i
Example 2: Algorithm check balanced parentheses
if (null == str || ((str.length() % 2) != 0)) {
return false;
} else {
char[] ch = str.toCharArray();
for (char c : ch) {
if (!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) {
return false;
}
}
}