You are viewing a single comment's thread. Return to all comments →
Can you explain why am I getting segmentation fault in this approach?
stack<char> s; int i, l = e.length(); char ch; for(i = 0;i<l;i++) { if(e[i] == '{' || e[i] == '[' || e[i] == '(') s.push(e[i]); else { if(e[i] == '}') { ch = s.top(); s.pop(); if(ch!='{') return false; } else if(e[i] == ']') { ch = s.top(); s.pop(); if(ch!='[') return false; } else if(e[i] == ')') { ch = s.top(); s.pop(); if(ch!='(') return false; } } } return (s.empty());
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
Can you explain why am I getting segmentation fault in this approach?