I have to write a function that accepts a string and returns a bool. The string passed in is a series or different parenthesis opened or closed ex.({[]}) and returns whether the 'parens' are well-balanced. This has to be implemented by adding items to a stack. I am getting the following error:
parenMatching_demo.cpp:18:12: error: no match for 'operator==' in 'c == '('
The psudocode is:
matcher(expression)
for each character in expression
if the character is an opener
push on stack
else if the character is a closr
if stack is empty return false
if the (opener at) the top of the stack does not match the closer
return false
pop the stack
if the stack is not empty return false
return true
This is what I have.
template <typename T>
bool parenMatching(string c) {
stack<string> s;
for (int i = 0; i < s.size(); i++) {
if (c == '(' || c == '[' || c == '{' || c == '<')
s.push(c);
else if (c == ')' || c == ']' || c == '}' || c == '>') {
if (s.empty()) return false;
if (s.top() != '(' || s.top() != '[' || s.top() != '{' || s.top() != '<')
return false;
s.pop();
}
}
}