steradsika.webblogg.se

Program For Evaluating Postfix Expression Using Stack In Java

Pushing the int 16 back onto the stack will allow you to pop 16 later, still as an int.

  1. java program to evaluate postfix expression using stack

I probably should have used the java implementation, but for this assignment I think I'll levae how I've done it so far.. Those 48 and 57 magic numbers are error-prone This is where I'm uncomfortable Program To Evaluate Postfix ExpressionI really didn't want to write the method this way, but at the time I had no idea how to handle it.. I already have a solution that works, but I feel that it's I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character '=' at the end.. Infix Expression Evaluation JavaPostfix Evaluation Using StackProgram To Evaluate Postfix ExpressionI'm trying to create a program that converts infix expression to postfix (using stack) and evaluate the result of the postfix expression.

java program to evaluate postfix expression using stack

java program to evaluate postfix expression using stack

I was trying to figure out if it was possible to do the evaluation with a 'char' stack, but I didn't see that working out since as far as I'm aware a char can only handle one character at a time - i.

Postfix Evaluation Using StackYou would have to check the switch and find whether the chars +-*/ are being automatically cast to ints.. At this point, when I evaluate 12+, it gives me 99 I know that's partly due to the decimal value of the char, but I'm really stuck on how to do this.

Wow, thanks for all the replies - I'm almost not sure where to start First thing, yes, I agree a switch statement would be much more useful here - I'll work on implementing that sometime when I get a chance.. Infix Expression Evaluation JavaThe question is: how do you do that? You already know the decimal value, so how do you think you might convert 48 to 0, 49 to 1.. Or more simply, if you use a stack of, and it works, then the cast is working all right.. The code inside each if is identical except for the result so, instead of the above, why not create a result() method; maybe something like: private static int result(char operator, int i1, int i2) {.. Just a question: Does the assignment includes writing a stack or is it ok to use the Java Stack implementation ()?? He wasn't clear with that, so I just wrote my own.. Those 48 and 57 magic numbers are error-prone There is a good reason for saying not to use numbers (except ±1 and 0). 5ebbf469cd