99 Elm Problems/Problem 68

68.a) Generate the preorder sequence of a tree. (Preorder processes each sub-tree <root> <left> <right>.) For example, the preorder sequence of the a(b(d,e),c(,f(g,))) is 'abdecfg'.

68.a) Generate the inorder sequence of a tree. (Inorder processes each sub-tree <left> <root> <right>.) For example, the preorder sequence of the a(b(d,e),c(,f(g,))) is 'abdecfg'.

68.c) Can you use preorder/2 from problem part a) in the reverse direction; i.e. given a preorder sequence, construct a corresponding tree? If not, make the necessary arrangements.

68.c) With both the preorder and inorder sequences of nodes a binary tree tree is determined unambiguously. Generate a tree from the preorder and inorder representations of a tree.

# # # THIS IS A STUB # # #

Example in Elm:
import Html exposing (text)
import List

f : Int -> Int
-- your implementation goes here

main = text (toString (f 0))

Result:

4

Solutions