The Shunting Yard Algorithm Demystified: Transform Expressions Like a Pro!

Поділитися
Вставка
  • Опубліковано 3 бер 2024
  • Welcome to my in-depth tutorial on the Shunting Yard Algorithm! 🚂💻 In this video, I unpack and explain this intriguing and useful algorithm. Designed by Edsger Dijkstra, this algorithm is a cornerstone for understanding expression evaluation and conversion, as it converts infix expressions to postfix (or Reverse Polish Notation) expressions.
    ---
    Source code: github.com/garyexplains/examp...
    Twitter: / garyexplains
    #garyexplains
  • Наука та технологія

КОМЕНТАРІ • 29

  • @tommurphy7157
    @tommurphy7157 2 місяці тому +1

    Brilliantly explained and very timely! Just what I needed to create the 'advanced' search for my app

  • @bendono
    @bendono 2 місяці тому +3

    I used RPN on my HP48G calculator while in high school. I also learned the Shunting Yard algorithm in my Computer Science degree; however, I guess I never really understood what "shunting yard" meant. It seems to be the British expression for a rail yard. I don't think it is a common term in US English. I recall classmates jokingly interpret it as "shatting yard" as in a place to to take shit.

  • @nickeax
    @nickeax 19 днів тому

    Thank you for the great presentation.

  • @muddyexport5639
    @muddyexport5639 2 місяці тому +2

    Excellent explanation and demo.

  • @user-jv1js9oc8l
    @user-jv1js9oc8l 2 місяці тому

    This was perfect timing thank you!

  • @alejandroguardiola9085
    @alejandroguardiola9085 Місяць тому

    Great video, but I have a question, in the explanation it seems like the output is a queue instead of a stack?

  • @berjancemdarc4345
    @berjancemdarc4345 18 днів тому

    What would this code do on situations like 10+2 ?

  • @bertblankenstein3738
    @bertblankenstein3738 2 місяці тому

    Once upon a time I coded a stack and the operators were numbers in an array of pointers to functions. I was kind of hoping to learn how this relates to railyards tho.

  • @kenc4026
    @kenc4026 25 днів тому

    Great work, sir. I got an idea because of this. Does this logic applies to Boolean Algebra too?

  • @Garythefireman66
    @Garythefireman66 2 місяці тому

    Thanks professor! 🤓

  • @AlwaysCensored-xp1be
    @AlwaysCensored-xp1be 2 місяці тому

    I wonder if LLM can solve those model train shunting games?

  • @HyyskanPolttaja
    @HyyskanPolttaja 2 місяці тому

    Great! But what about square roots & stuff?

    • @GaryExplains
      @GaryExplains  2 місяці тому +1

      For other operations you would use functions like cos (), sqrt(), etc. This is how you could write a compiler or interpreter using this method. It is the same principle. Functions have a lower precedence than plus and minus. Raise-to-power ^ has the highest precedence.

  • @uvatham
    @uvatham 2 місяці тому +1

    00:06

  • @CanadianBakin42O
    @CanadianBakin42O 2 місяці тому

    FÍRST!

  • @sssyt4837
    @sssyt4837 2 місяці тому

    First!

  • @K9-33
    @K9-33 2 місяці тому

    Just use the FORTH programming language.

    • @GaryExplains
      @GaryExplains  2 місяці тому

      That isn't the point. The point is to know how to do it yourself.

  • @LA-MJ
    @LA-MJ 2 місяці тому

    Exit takes an exit code not a calculation result 😂

    • @GaryExplains
      @GaryExplains  2 місяці тому

      And why can't the exit code be a calculation result?

    • @LA-MJ
      @LA-MJ 2 місяці тому

      @@GaryExplainsbecause non-zero exit code means error occurred in standard semantics

    • @GaryExplains
      @GaryExplains  2 місяці тому

      No, not necessarily. If you want a program to calculate something it can return the calculation as an exit code. This is very useful for scripting. You are making an assumption about the return codes, I assume based on Unix/Linux. On VMS for example SUCCESS was never 0.

    • @LA-MJ
      @LA-MJ Місяць тому

      @@GaryExplainsof course it's UNIX. Which matters more