% Solution to assignment 4, by Phil Edmonds % % this includes just the functions you had to write, not the whole class %----------------------------------------------------- % Function that returns the number of leaves in a tree % (Recursive) %----------------------------------------------------- function recCountLeaves (curr : ^nodeType) : int if curr = nil then result 0 elsif curr -> left = nil and curr -> right = nil then result 1 else result recCountLeaves (curr -> left) + recCountLeaves (curr -> right) end if end recCountLeaves %-------------------------------------- % Counts the number of leaves in a tree %-------------------------------------- function CountLeaves : int result recCountLeaves (root) end CountLeaves