Skip to content

Commit ea0df5b

Browse files
committed
Fixed some typos
1 parent edf5673 commit ea0df5b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Shunting Yard/README.markdown

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Any mathematical expression that we write is expressed in a notation known as In
44

55
For example:
66

7-
A + B * C
7+
**A + B * C**
88

99
In the above expression the operator is placed between operands hence the expression is said to be in Infix form.
1010
If you think about it any expression that you write on a piece of paper will always be in infix form. This is what we humans understand.
1111

1212
Now, think about the way the above expression is evaluated, you would first multiply B and C then add the result to A. This is because multiplication has
1313
higher precedence than addition. We humans can easily understand the precedence of operators, but a machine needs to be given instructions about each operator. If you were to
14-
write an algorithm than parsed and evaluated the infix notation you'll soon realize that it's a tedious process. You'd have to parse the expression
14+
write an algorithm that parsed and evaluated the infix notation you will realize that it's a tedious process. You'd have to parse the expression
1515
multiple times to know what operation to perform first. As the number of operators increase so does the complexity.
1616

1717
## Postfix notations / Reverse Polish Notation
@@ -29,16 +29,13 @@ The above is the postfix representation of the example in the previous section.
2929

3030
A stack is used to evaluate a postfix expression. Here is the pseudocode:
3131

32-
1. read postfix expression token by token
33-
2. if the token is an operand, push it
34-
into the stack
35-
3. if the token is a binary operator,
36-
3.1 pop the two top most operands
37-
from the stack
38-
3.2 apply the binary operator with the
39-
two operands
40-
3.3 push the result into the stack
41-
4. finally, the value of the whole postfix
32+
1. Read postfix expression token by token
33+
2. If the token is an operand, push it into the stack
34+
3. If the token is a binary operator,
35+
1. Pop the two top most operands from the stack
36+
2. Apply the binary operator with thetwo operands
37+
3. Push the result into the stack
38+
4. Finally, the value of the whole postfix
4239
expression remains in the stack
4340

4441
Using the above psuedocode the evaluation on the stack would be as follows:
@@ -105,4 +102,11 @@ The above table describes the precedence and the associativity for each operator
105102
| - | Push token to stack | 4 4 2 * 1 | - ( / + |
106103
| 5 | Add token to output | 4 4 2 * 1 5 | - ( / + |
107104
| ) | * Pop stack to output * Pop stack | 4 4 2 * 1 5 - | / + |
108-
| end | Pop entire stack to output | 4 4 2 * 1 5 - / + | |
105+
| end | Pop entire stack to output | 4 4 2 * 1 5 - / + | |
106+
107+
108+
# See Also
109+
110+
[Shunting yard algorithm on Wikipedia](https://en.wikipedia.org/wiki/Shunting-yard_algorithm)
111+
112+
*Written for the Swift Algorithm Club by [Ali Hafizji](http://www.github.com/aliHafizji)*

0 commit comments

Comments
 (0)