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 - Наука та технологія
Brilliantly explained and very timely! Just what I needed to create the 'advanced' search for my app
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.
Thank you for the great presentation.
Excellent explanation and demo.
Glad you liked it!
This was perfect timing thank you!
So glad!
Great video, but I have a question, in the explanation it seems like the output is a queue instead of a stack?
What would this code do on situations like 10+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.
Great work, sir. I got an idea because of this. Does this logic applies to Boolean Algebra too?
i think so
Thanks professor! 🤓
My pleasure!
I wonder if LLM can solve those model train shunting games?
Great! But what about square roots & stuff?
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.
00:06
🚂
🤣
FÍRST!
First!
Just use the FORTH programming language.
That isn't the point. The point is to know how to do it yourself.
Exit takes an exit code not a calculation result 😂
And why can't the exit code be a calculation result?
@@GaryExplainsbecause non-zero exit code means error occurred in standard semantics
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.
@@GaryExplainsof course it's UNIX. Which matters more