bracket balancing c 2b 2b

Solutions on MaxInterview for bracket balancing c 2b 2b by the best coders in the world

showing results for - "bracket balancing c 2b 2b"
Guadalupe
19 Apr 2018
1/*
2PARENTHESE MATCHING
3AUTHOR: UTKARSH SINHA
4*/
5bool correct_paranthesis(string str){
6	stack<char> stk;
7	map<char,char> bracket_map;
8	bracket_map[')'] = '(';
9	bracket_map['}'] = '{';
10	bracket_map[']'] = '[';
11	
12	for(int i=0; i<str.size(); i++){
13		if(str[i] == '(' || str[i] == '{' || str[i] == '[')
14			stk.push(str[i]);
15		if(str[i] == ')' || str[i] == '}' || str[i] == ']'){
16			if(stk.empty())
17				return false;
18			if(stk.top() == bracket_map[str[i]] )
19				stk.pop();
20		}
21	}
22	
23	return (stk.empty() == true);
24}