I Need A Code In C++ Language Programming Like This To Evaluate The postfix expression if all bracket not missing do the evaluate if any bracket missing will program give me mising open bracket or close bracket please\ Data Structure using c++ (stack) like this function but i need a simple one please  int evaluator(string tokens){ int i; int op_brace =0; int closing_brace = 0; stack values; stack ops; for(i = 0; i < tokens.length(); i++) { if(tokens[i] == ' ') continue; else if(tokens[i] == '('){ ops.push(tokens[i]); op_brace ++; } else if(isdigit(tokens[i])){ int val = 0; while(i < tokens.length() && isdigit(tokens[i])){ val = (val*10) + (tokens[i]-'0'); i++; } values.push(val); i--; } else if(tokens[i] == ')'){ closing_brace++; if(closing_brace > op_brace){ cout<<"\n missing open bracket"<= precedence(tokens[i])){ int val2 = values.top(); values.pop(); int val1 = values.top(); values.pop(); char op = ops.top(); ops.pop(); values.push(operation(val1, val2, op)); } ops.push(tokens[i]); } } if(op_brace>closing_brace) { cout<<"\n missing close bracket"<op_brace) { cout<<"\n missing open bracket"<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I Need A Code In C++ Language Programming Like This To Evaluate The postfix expression if all bracket not missing do the evaluate if any bracket missing will program give me mising open bracket or close bracket please\

Data Structure using c++ (stack)

like this function but i need a simple one please 

int evaluator(string tokens){
int i;
int op_brace =0;
int closing_brace = 0;
stack <int> values;
stack <char> ops;

for(i = 0; i < tokens.length(); i++)
{
if(tokens[i] == ' ')
continue;
else if(tokens[i] == '('){
ops.push(tokens[i]);
op_brace ++;
}
else if(isdigit(tokens[i])){
int val = 0;
while(i < tokens.length() &&
isdigit(tokens[i])){
val = (val*10) + (tokens[i]-'0');
i++;
}
values.push(val);
i--;
}

else if(tokens[i] == ')'){
closing_brace++;
if(closing_brace > op_brace){
cout<<"\n missing open bracket"<<endl;

exit(0);

}
while(!ops.empty() && ops.top() != '(')
{
int val2 = values.top();
values.pop();

int val1 = values.top();
values.pop();

char op = ops.top();
ops.pop();

values.push(operation(val1, val2, op));
}
if(!ops.empty())
ops.pop();
}
else{
while(!ops.empty() && precedence(ops.top())
>= precedence(tokens[i])){
int val2 = values.top();
values.pop();

int val1 = values.top();
values.pop();

char op = ops.top();
ops.pop();

values.push(operation(val1, val2, op));
}
ops.push(tokens[i]);
}
}
if(op_brace>closing_brace)
{
cout<<"\n missing close bracket"<<endl;

exit(0);
}
else if(closing_brace>op_brace)
{
cout<<"\n missing open bracket"<<endl;

exit(0);
}
while(!ops.empty()){
int val2 = values.top();
values.pop();

int val1 = values.top();
values.pop();

char op = ops.top();
ops.pop();

values.push(operation(val1, val2, op));
}

return values.top();
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education