-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
In the Shunting Yard Algorithm video, we give + a higher precedence than -. Whilst this is usually fine, there's an issue here.
Consider the expression 1 - 2 + 3. Mathematically, if we were to add then subtract, what we want to be doing is -2 + 3. What the code does in this case instead is 2 + 3. This means that we end up doing 1 - 5, rather than 1 + 1, which is incorrect.
The easiest solution would be to give + and - the same precedence, and for the sake of consistency also give * and / the same precedence. Alternatively we'd need to check whether the first parameter is part of a subtraction, which can be a little finnicky.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels