0

有人可以给我提供伪代码吗?我不能使用 for,while 等。我只能调用我的函数。

4

1 回答 1

1

If you want to get all child nodes of an arbitrary binary tree node, you may do this:

(define (traverse node)
  (cond ((null? node) '())
        ((not (pair? node)) node)
        (else (cons (traverse (left-child node))
                    (traverse (right-child node))))))

For N-ary tree you could use kind of get-child functions instead of left and right child functions.

于 2013-01-10T15:23:22.073 回答