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
0
votes
2 answers

Understanding the Clojure way

I'm really interested in becoming proficient in Clojure/Clojurescript for web applications. Right now I'm making simple command-line applications to get a feel for the language. But right now it's hard to grasp the workflow of how to get things done…
Emil
  • 447
  • 4
  • 18
0
votes
1 answer

Clojure PN (java.lang.ClassCastException)

I'm using Clojure for a code golf challenge, in which the aim is to write a function that evaluates and returns the value from a Polish Notation expression. Below is my code. (require '[clojure.string :as s]) (defn p[e]( (load-string (reduce…
Dan Prince
  • 29,491
  • 13
  • 89
  • 120
0
votes
1 answer

Infix to Postfix notation C++

Hello Stack I'm curently atempting to write a RPN converter and I'm new to C++. But I'm running into problems. Hopefully I can explain the problems in detail. Im using an array for stacking my operators. Lets use the example "5 + 8" When I get down…
Conor
  • 640
  • 5
  • 10
  • 21
0
votes
1 answer

Convert infix to RPN (shunting yard)

Here is my code to convert infix to RPN using shunting yard. I know how the algorithm works well and I have no problem with that, but when I run this just nothing happens. When I debug it I get unknown error on stack initialization line. #include…
PedramH
  • 123
  • 1
  • 8
0
votes
2 answers

Use of $ in postfix expression

The value of the postfix expression 8 3 4 + - 3 8 2 / + * 2 $ 3 + is: a) 17 b) 131 c) 64 d) 52 Prefix of A-B/C*D$E is: a)-/*$ACBDE b)-ABCD*$DE c)-A/B*C*$DE d)-A/BC*$DE Can anybody explain to me how to solve these expressions when a $ sign is…
C_beginner
  • 305
  • 1
  • 4
  • 12
0
votes
3 answers

Trying to evaluate an expression

I'm working on an RPN Calculator and think I'm almost there, except it's returning the expression not the solution. def evaluate(expression) expression = expression.split operators = expression.select { |v| v =~ /\W/} operands =…
0
votes
1 answer

Reverse algorithm to reverse polish notation

I know how RPN works, i.e. we have input: a + b * c and output is bc*a+ Is it easy to create algorithm which shows me what is the last computation of this equation? I mean that I want to know that first operation is + on two sentences: "a" and…
Andrzej
  • 561
  • 1
  • 7
  • 22
0
votes
2 answers

RPN calculator doesn't perform calculations correctly

I have a program that is supposed to convert an expression into reverse polish notation, and then display the answer after performing the calculations. Right now it doesn't perform calculations correctly. For example, if I enter 5+2+5, it only…
Dorden
  • 45
  • 7
0
votes
1 answer

Reverse Polish Notation Java

I want to make Reverse Polish Notation algorithm, but my code isn't working. Can anyone explain me why ? In my code, I would like to take the characters, until "/+-*"tokens . If this tokens was next , make operation , that contains in case . import…
MOnasz
  • 99
  • 1
  • 2
  • 8
0
votes
1 answer

Java RPN Calculator Null pointer issue

Hi I have managed to fix the null pointer issue. Now I have almost got the code working except when it is evaluating I am getting the answer for every equation as 15? My TestClass is shown below: import java.io.BufferedReader; import…
Ph9
  • 85
  • 1
  • 2
  • 10
0
votes
2 answers

How to pass a stack into a method

I am rebuilding a stack calculator so it is recursive. However, I get an error: stacks2.java:29: illegal start of expression public calculate(Stack stack) { ^ stacks2.java:29: ';' expected public calculate(Stack stack) { How are…
user1093111
  • 1,091
  • 5
  • 21
  • 47
0
votes
1 answer

Invalid rpn expression in rrdtool, containing several LT and IF in a CDEF

I'm trying to create a graph with multiple data sources and I'm trying to get the minimal value of all of them. I've tried with two data sources, it's working. Below the version with 2 data sources…
Doomsday
  • 2,650
  • 25
  • 33
0
votes
2 answers

atoi not converting string properly?

So, I have the following (kludgy!) code for an infix to postfix expression converter and calculator (as I mentioned on my previous post: Simple numerical expression solver, thanks to everyone!): #include #include #include…
segfaultd
  • 143
  • 3
-1
votes
1 answer

Normal to RPN conversion

I have a question. Is (3+4)*(5+6+7*8)*(1*9+2*8) equal to 34 + 56 + 78 + * + 19 * 28 * + * in RPN notation?
mmm
  • 1
  • 1
-1
votes
1 answer

RPN in "The C Programming Language" book 2nd edition section 4.3, numbers not being pushed to stack

I have been reading through the C programming Langauge book and in section 4.3 I am trying to compile and run the code thats provided in pages 76-79. I think I have done exactly what is in the textbook, but its not working as it should. From some…
theperson
  • 3
  • 4