Tuesday, August 04, 2015

mirror a binary tree

mirror-main(n):
    if n == null:
        throw
    return mirror(n)

mirror(n):
    if n == null:
        return null
    n' = new node(n.value)
    n'.left = mirror(n.right)
    n'.right = mirror(n.left)
    return n'

No comments:

Post a Comment