Shunting-yard Algorithm - A Simple Conversion

A Simple Conversion

Input: 3+4
  1. Add 3 to the output queue (whenever a number is read it is added to the output)
  2. Push + (or its ID) onto the operator stack
  3. Add 4 to the output queue
  4. After reading the expression pop the operators off the stack and add them to the output.
  5. In this case there is only one, "+".
  6. Output 3 4 +

This already shows a couple of rules:

  • All numbers are added to the output when they are read.
  • At the end of reading the expression, pop all operators off the stack and onto the output.

Read more about this topic:  Shunting-yard Algorithm

Famous quotes containing the words simple and/or conversion:

    And would you be a poet
    Before you’ve been to school?
    Ah, well! I hardly thought you
    So absolute a fool.
    First learn to be spasmodic—
    A very simple rule.
    For first you write a sentence,
    And then you chop it small;
    Then mix the bits, and sort them out
    Just as they chance to fall:
    The order of the phrases makes
    No difference at all.
    Lewis Carroll [Charles Lutwidge Dodgson] (1832–1898)

    The conversion of a savage to Christianity is the conversion of Christianity to savagery.
    George Bernard Shaw (1856–1950)