I'm trying to implement prefix to infix in c++, that's what i've got so far. The input should be for example something like this:
/7+23 And the ouput:
7/(2+3) or (7/(2+3)) But instead I get:
(/) That's the code I wrote so far:
void pre_to_in(stack<char> eq) { if(nowe.empty() != true) { char test; test = eq.top(); eq.pop(); if(test == '+' || test == '-' || test == '/' || test == '*') { cout << "("; pre_to_in(eq); cout << test; pre_to_in(eq); cout << ")"; } else { cout << test; } } } // somewhere in main() char arr[30]; stack<char> stosik; int i = 0; cout << "write formula in prefix notation\n"; cin >> arr; while(i < strlen(arr)) { stosik.push(arr[i]); i++; } pre_to_in(stc);