I am trying to implement a Shunting-yard algorithm without parentheses, but I find it hard to understand. I tried wikipedia, but the record is really bad. I would not have problems implementing the code, but if I donβt get it, I wonβt be able to implement it.
Now: how does this algorithm work?
Here is what I understand:
Scroll from left to right, all numbers are added to the output queue, all operands are added to the stack. Once you reach the end, you will put all the operands and add them to the output file
Expression: 2+5*4+3/5 ( = 2+20+0.6 = 22.6 ) Stack: +*+/ ( -> top ) OutputQueue: 5 3 4 5 2 ( -> exits)
Now I pop the stack and add it to the queue
OutputQueue: (insert ->) + * + / 5 3 4 5 2 ( -> exit)
So, as far as I understand, the form should be: 25435 / + * +
Let's try and decide:
5/3 ~ 1.6 + 4 ~= 5.6 * 5 ~= 28 + 2 ~= 30 (or 30.3 recurring .3 if you insist)
EDIT: I am sure the reverse Polish notation I used here is correct, so this should not be a question.
I know that I am doing something stupid, but for life I can not understand.
I think this will help the majority if someone can point out an error in my logic, because the algorithm should be good, since it is from Wikipedia, and I saw others pointing me to this. So it should be fine, I just ruined something.
Is this the turn? I'm sure I handle Reverse Polish notation quite well.
Kalec source share