Questions tagged [rpn]

For questions relating to the Reverse Polish Notation, which is a notation for mathematical expressions where the operands precede the operator.

In computing, RPN is ideally suited for a stack-based implementation, and in hardware it has a long history with HP hand-held calculators.

E.g. 1 2 + means apply the + operator to the operands 1 and 2.

198 questions
1
vote
0 answers

Infix to Postfix Notation Parentheses issue

So I am currently working on a project to convert infix to postfix notation and I am almost finished with the project. It correctly converts infix to postfix until I try adding parentheses it ends up incorrectly formatted. static int…
1
vote
0 answers

Precedence of operators on RPN calculator power is not working

the result and everything was working for any input other than power(^) and modulo(%) operator can anyone tell me where my mistake is. here is my Github link: https://github.com/mikiyas-ahmed/RPN/tree/master/RPN/src if the input is 3*(2+3)-7+8*8 it…
maik_eshe
  • 19
  • 4
1
vote
0 answers

Polish notation to reverse polish notation

I have a working piece of code for calculating polish notation, would there be any way to change the code i have currently to perform reverse polish notation or will it need to be a different solution entirely. Thanks. import…
Gaben
  • 21
  • 3
1
vote
1 answer

Stucked with Reverse Polish Notation

I'm having a homework: When we input the math expression like -(2 + 3) * 1/5 , the output should be -1. After doing some research, I found that RPN algorithm is the way to solve this problem. So what I did is convert the expression from infix to…
TamTam
  • 547
  • 1
  • 5
  • 16
1
vote
1 answer

How to fix Segmentation Fault while trying to do RPN in C

I am trying to make a program that will use RPN, which will calculate a series of integers. I have some standard functions (pop, push) that I can't change. But when I run the below code, I get a segmentation fault. Since I can't change the inside…
laland
  • 61
  • 1
  • 9
1
vote
1 answer

Trying to convert infix to postfix returns backwards output

I am creating a Reverse Polish Notation calculator that converts an infix expression to a postfix expression. However, my operators are outputting backwards. For example, I have entered the infix as "1+5*(3*2)" and when I run the program, I get the…
suicuned
  • 37
  • 5
1
vote
2 answers

how do I add unary operator for RPN algorithm that calculates postfix expression in java

I have to create an application which calculates postfix expressions. I was able to find it online (rosetta code) but it's missing a unary operator. the symbol "~" is supposed to denote the unary operator I tried adding it but unfortunately it…
Osama
  • 23
  • 4
1
vote
2 answers

Need help putting radial distant into reverse polish notion for a lisp program

The distance formula for polar coordinated is shown here: http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distancepolar.htm I've tried doing it this way: (defun distant-formula (r1 r2 t1 t2) (setq d ( sqrt (*(-(+ (expt r1 2)(expt r2 2))(*…
Bob gilong
  • 215
  • 2
  • 8
  • 17
1
vote
0 answers

How do I simulate user input to a console application from Unit Test project?

I am trying to write a text processing console application in C++ and I have met Windows API for the first time. But before defining a grammar or using the existing bison/flex or boost tools I want to realize a TDD approach and write all tests and…
1
vote
1 answer

Converting postfix (reverse polish notation) expressions to infix with minimal parentheses

I am looking for an algorithm to convert a postfix expressions to infix expressions but with minimal parentheses. I am asking it here after searching Google Stack Overflow. I only found a single answer to my question but it was in Java and I don't…
1
vote
1 answer

RPN Calculator using Scanner, If/Else statement not reading

I am working on a very simple reverse polish notation calculator using stacks, and having trouble with an if/else statement inside a while loop. The rest of the code is working correctly, but I keep getting a NumberFormatException after the else…
1
vote
3 answers

Abort evaluation of boolean RPN expression

I have a few boolean expression in RPN-Format like this: {0} {1} {2} AND OR // equals: {0} or {1} and {2} Computing the boolean variables {x} is very expensive. And obviously there is no need to compute {1} and {2} if {0} is already true, since…
user2033412
  • 1,950
  • 2
  • 27
  • 47
1
vote
0 answers

Optimal way of evaluating RPN (postfix) expressions

Working on a small project, I stumbled across the problem that I cannot find an efficient way of parsing mathematical expressions in Python. Briefly about the context: the program relies on iterating over a very large (~10 million) number of…
IliaK
  • 19
  • 2
1
vote
1 answer

converting numeric members of a string (type char) to type int in C: RPN interpreter

I'm currently trying to create a Reverse-Polish notation interpreter in C, using a stack implemented using struct. It should take all single-digit values (0-9) and the operators +,-,* and /, and reject all others by exiting the program. I am trying…
Thefoilist
  • 137
  • 1
  • 11
1
vote
4 answers

Can all RPN expressions be represented such that all operators appear on the left and all operands appear on the right?

I've convinced myself that they can't. Take for example: 4 4 + 4 / stack: 4 stack: 4 4 4 + 4 = 8 stack: 8 stack: 8 4 8 / 4 = 2 stack: 2 There are two ways that you could write the above expression with the same operators and operands such that the…
kanske
  • 13
  • 1
  • 2