stack data structure c++
/*
* Complete the 'isBalanced' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
string isBalanced(string s) {
stack<char> c;
for(int i=0;i<s.length();i++)
{
if(s[i]=='('||s[i]=='{'||s[i]=='[')
{
c.push(s[i]);
}
if(!c.empty())
{
if(s[i]==')')
{
if(c.top()=='(')
{
c.pop();
continue;
}else
{
break;
}
}
//
if(s[i]=='}')
{
if(c.top()=='{')
{
c.pop();
continue;
}else
{
break;
}
}
//
if(s[i]==']')
{
if(c.top()=='[')
{
c.pop();
continue;
}else
{
break;
}
}
}else
{
return "NO";
}
}
return c.empty()? "YES":"NO";
}