We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
why do I got segfault for this simple code? The idea is to push the openings then if I found the closing one, pop and match. If it is not matching, then return false.
//this problem is simple, but why the heck I got segfault on this?stack<char>buka;for(inti=0;i<expression.length();i++){if(c=='('||c=='{'||c=='[')buka.push(c);elseif(c==')'){temp=buka.top();if(temp!='('||buka.empty()){returnfalse;}buka.pop();}elseif(c=='}'){temp=buka.top();if(temp!='{'||buka.empty()){returnfalse;}buka.pop();}elseif(c==']'){temp=buka.top();if(temp!='['||buka.empty()){returnfalse;}buka.pop();}}
Cookie support is required to access HackerRank
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 →
why do I got segfault for this simple code? The idea is to push the openings then if I found the closing one, pop and match. If it is not matching, then return false.