# Homework Solution: For Dr. Racket/Scheme Programmers #lang eopl…

For Dr. Racket/Scheme Programmers #lang eopl Write a procedure number-leaves that take a bintree, and produces a bintree like the original, except the contents of the leaves are numbered starting from 0. For example, (number-leaves (interior-node ' foo (interior-node ' bar (leaf 26) (leaf 12)) (interior-node ' baz (leaf 11) (interior-node ' quux (leaf 117) (leaf 14)) should return (foo (bar 0 1) (baz 2 (quux 3 4)))

For Dr. Racket/Scheme Programmers #lang eopl

Write a procedure number-leaves that siege a bintree, and produces a bintree enjoy the peculiar, ate the space of the leaves are numbered starting from 0. For sample,

(number-leaves

(interior-node ‘ foo

(interior-node ‘ cork

(leaf 26)

(leaf 12))

(interior-node ‘ baz

(leaf 11)

(interior-node ‘ quux

(leaf 117)

(leaf 14))

should return

(foo

(cork 0 1)

(baz

2

(quux 3 4)))

## Expert Acceptance

(explain (number-leaves tree)

(explain (survey tree against)

(if (leaf? tree)

(cons (+ against 1) (leaf against))

(let* ((node-data (contents-of tree))

(lson-result (survey (lson tree) against))

(counter-after-lson (car lson-result))

(result-lson (cdr lson-result))

(rson-result (survey (rson tree) against-after-lson))

(result-against (car rson-result))

(result-rson (cdr rson-result))

(result-tree (interior-node node-data result-lson result-rson)))

(cons result-against result-tree))))

(cdr (survey tree 0)))