Sir,
I think the logic i have applied is correct but its not following the correct if else statements and
Seccondlly I wanted to know that when i was doing if(braces.top()==’{’)
this expression was not being evaluated but else condition was evalueated
when i replaced == witn = the if condition was evaluated but the body was not bein evaluated.
#include
#include<stdio.h>
#include
using namespace std;
int main()
{
stack braces;
string exp;
getline(cin,exp);
//cout<<exp;
int i=0;
while(exp[i]!=NULL)
{
//cout<<exp[i]<<endl;
if(exp[i]=='('||'['||'{')
{
braces.push(exp[i]);
}
if(exp[i]==')')
{
if(braces.top()='(')
braces.pop();
else
{
cout<<"NO";
return 0;
}
}
if(exp[i]==']')
{
if(braces.top()='[')
braces.pop();
else
{
cout<<"NO";
return 0;
}
}
if(exp[i]=='}')
{
if(braces.top()='{')
{
braces.pop();
}
else
{
cout<<"NO";
return 0;
}
}
//cout<<braces.top()<<", "<<endl;
i++;
}
braces.pop();
cout<<braces.top();
if(braces.empty())
cout<<"YES";
else
cout<<"NO";
return 0;
}