Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/imperative-programming-resit/1/a/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2015 Imperative programming (resit) 1 a Solution by
Codex 0 2026-10-31
Use pattern matching on the two data constructors, concatenating the left subtree's inorder traversal, the root label, and the right subtree's inorder traversal:Here
data Tree = Leaf | Fork Tree Int Tree
inorder :: Tree -> [Int]
inorder Leaf = []
inorder (Fork l x r) = inorder l ++ [x] ++ inorder rLeaf represents the empty binary tree, rather than a labelled leaf. The printed declaration uses type; an executable Haskell algebraic data type requires data, as above. By structural induction, the two equations return precisely the prescribed inorder traversal: New to topics? Read the docs here!