int main() {
stack<char> s;
string str;
cin >> str;
for(int i=0;i<str.length();i++) {
char ch = str[i];
if(ch == '(') {
s.push(ch);
} else if(ch == ')'){
if(s.top() == '(') {
s.pop();
} else {
cout << "Not Balanced";
return 0;
}
}
}
if(s.size() == 0) cout << "Balanced";
else cout << "Not Balanced";
return 0;
}
This is should give Not Balanced for string ()) .
It is crashing unexpectedly.Why?