C ++でプレフィックスをインフィックスに実装しようとしていますが、これがこれまでのところです。入力は、たとえば次のようにする必要があります。
/7+23
そして出力:
7/(2+3) or (7/(2+3))
しかし、代わりに私は得る:
(/)
それが私がこれまでに書いたコードです:
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);