needs correction doesnt run
needs correction doesnt run
#include <iostream>
#include <stack>
using namespace std;
int matchingBracketsstringexprstringexprstringexpr
{
stack<char> s;
char x;
for inti=0;i<expr.length(inti=0;i<expr.length(inti=0;i<expr.length(; i++)
{
if expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain([Math Processing Error]expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain(
{
string expr;
int res;
getline(cin,exprcin,expr)cin,expr);
res=matchingBracketsexprexpr;
if res==0res==0
cout << "No mistake";
else
cout << res;
return 0;
}
Step by step
Solved in 2 steps