Write a program that converts an infix expression into an equivalent postfix expression.
Your answer must be something similar to the following form:
Infix Expression: ((A + B) - C);
Postfix Expression: A B + C -
And keep in mind that its will be based on these:
b. If Token is(i) a left parenthesis: Push it onto the stack(ii) a right parenthesis: Pop and display stack elements until a left parenthesis is popped, but do not display it. (It is an error if the stack becomes empty with no left parenthesis found.)(iii) an operator: If the stack is empty or
Token has a higher priority than the top stack, push Token onto the stack. Otherwise, pop and display the top stack
element: then repeat the comparison of Token
with the new top stack item. A left parenthesis in the stack is assumed to have a lower priority than that of operators.(iv) an operand: Display it.
Your line is evaluating line[i]=='*' and then or-ing that with '/' and '%', which are both non-zero and therefore equivalent to zero. (That is, operator== can only compare one thing at a time)
#2 The same deal with line
if (line[i]=='+'||'-')
#3 The line
cout<<line[i];
looks like it just prints out the whole of the original string?
But I note that your problem statement refers to tokens whereas you're working with chars. They're not generally the same thing.
Andy
PS See this page for how to use formatting tags (and ideally go back and edit your post to use them)
#3 the line
cout <<line[i];
is based on:
operators.(iv) an operand: Display it.
thank u i got what u just said but would please explain how to do this one
(iii) an operator: If the stack is empty or
Token has a higher priority than the top stack, push Token onto the stack. Otherwise, pop and display the top stack
element: then repeat the comparison of Token
with the new top stack item. A left parenthesis in the stack is assumed to have a lower priority than that of ???