I am working on a binary tree class for one of my algorithms class. I have gone a little off the rails and implemented generators for the different tree traversal techniques.

One thing I don't like though is all the redundancy. All of these generators are essentially the same but just the order in which nodes and trees are evaluated is changed. Is there anyway to simplify the code or reduce the redundancy?

Python snippet that shows the implementation of tree traversal algorithms for inorder, preorder, postorder, and level-order
0

If you have a fediverse account, you can quote this note from your own instance. Search https://tiggi.es/users/athousandcateaus/statuses/115215892577627231 on your instance and quote it. (Note that quoting is not supported in Mastodon.)