Note that there are some explanatory texts on larger screens.

plurals
  1. POinfix to postfix converter using stack
    text
    copied!<p>I want to convert infix to postfix expression. This is my code:</p> <p>The problem is that this actually doesn't do so and I am confused why. Everything makes sense to me but when i input for example <code>4*5</code> as an output i get the same thing. infix is an input and postfix is what i want to return as a pointer to postfix so it can be then evaluated.</p> <p>operand returns true if it is * - + or /</p> <p>UPDATE:</p> <p>oki i got it working but i have trouble figuring out what if you input like 5 * 3 + -1.2 then its not gonna work if you want to have like negative number.</p> <pre><code>void infix2postfix(char* infix, char* postfix){ char *in,*post; Stack&lt;char&gt;Q; char n; in = &amp;infix[0]; post = &amp;postfix[0]; while(*in){ while(*in == ' ' || *in == '\t'){ in++; } if( isdigit(*in) || isalpha(*in) ){ while( isdigit(*in) || isalpha(*in)){ *post = *in; post++; in++; } } if( *in == '(' ){ Q.Push(*in); in++; } if( *in == ')'){ n = Q.Pop(); while( n != '(' ){ *post = n; post++; n = Q.Pop(); } in++; } if( operand(*in) ){ if(Q.IsEmpty()) Q.Push(*in); else{ n = Q.Pop(); while(priority(n) &gt;= priority(*in)){ *post = n; post++; n = Q.Pop(); } Q.Push(n); Q.Push(*in); } in++; } } while(!Q.IsEmpty()) { n = Q.Pop(); *post = n; post++; } *post = '\0'; } </code></pre> <p>here is my code new code, it works but I want it to to work with unary operators so it would take the input <code>4 * 5 + 4 + -1.2</code>, so there is a space between and if there is not then it is for example -1.2 negative number. also my code doesn't work for an integer which is more than 9, if i put 10 then it just multiplies 1*0. .</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload