C++ (The referencing style doesn't matter, idk why I had to fill that out) I was wondering if there was any way this code can be altered, maybe changing the if else statements to switch statements...

1 answer below »
C++ (The referencing style doesn't matter, idk why I had to fill that out)
I was wondering if there was any way this code can be altered, maybe changing the if else statements to switch statements or anything else? I couldn't figure it out and I don't want to be flagged for my assignment for similarity.
#include #include #include
using namespace std;
int prec(char c){ if(c=='^'){ return 3; } else if(c=='/'||c=='*'){ return 2; } else if(c=='-'||c=='+'){ return 1; } else{ return -1; }}
void infToPostfix(string d) {
stack a; string result;
for (int i = 0; i char c = d[i]; if (c != ' ') { if ((c >= 'a' && c XXXXXXXXXXresult += c; XXXXXXXXXXresult+=" "; } else if (c == '(') { XXXXXXXXXXa.push('('); } else if (c == ')') { XXXXXXXXXXwhile (a.top() != '(') { XXXXXXXXXXresult += a.top(); XXXXXXXXXXresult+=" "; XXXXXXXXXXa.pop(); } XXXXXXXXXXa.pop(); } else { XXXXXXXXXXwhile (!a.empty() && prec(d[i] XXXXXXXXXXresult += a.top(); XXXXXXXXXXresult+=" "; XXXXXXXXXXa.pop(); } XXXXXXXXXXa.push(c); } }

} while (!a.empty()) { result += a.top(); result+=" "; a.pop(); }
cout }






Answered Same DayApr 04, 2022

Solution

Kshitij answered on Apr 04 2022
13 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here