You are viewing a single comment's thread. Return to all comments →
so what's the solution? ... i tried putting in underflow condition but am unable to make it work.. can you help me.? here's my code:
class stck{ int top; char st[1001]; public: stck(){top=-1;} void push(char item){ top++; if(top<1001) st[top] = item; else top--; } char pop(){ top--; return st[top+1]; } }; bool is_balanced(string expression) { stck s; char c; int i=0; while(expression[i]){ if(expression[i]!='}' && expression[i]!=']' && expression[i]!=')' ) s.push(expression[i]); else{ c = s.pop(); switch (c){ case '{': if(expression[i]!='}') return 0; else break; case '[': if(expression[i]!=']') return 0; else break; case '(': if(expression[i]!=')') return 0; else break; } } i++; } return 1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Stacks: Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
so what's the solution? ... i tried putting in underflow condition but am unable to make it work.. can you help me.? here's my code: