News for hackers. Stuff that matters.
Re:Tree traversal without recursion: the tree as a state mac... by segmondy on Tuesday September 03, 2019 @02:06AM (#20864050)
Learn some Prolog, one of the best langauge for studying your algorithms and data structures. https://rosettacode.org/wiki/Tree_traversal#Prolog

preorder(nil). preorder([Node, FG, FD]) :- format('~w ', [Node]), preorder(FG), preorder(FD).

inorder(nil). inorder([Node, FG, FD]) :-inorder(FG), format('~w ', [Node]), inorder(FD).

postorder(nil). postorder([Node, FG, FD]) :-postorder(FG), postorder(FD),format('~w ', [Node]).

There are no comments on this comment yet.