Wednesday, November 14, 2012

A Correction

I noticed a problem with the binary-tree walk subroutine, so I'm reposting both corrected versions.

Walk

Version 1:

    subroutine walk
        given:
            Node tree
        returns:
            List values

        if not empty tree:
            push values, filter not empty, walk tree.left, tree.value, walk tree.right

    return values

Version 2:

    subroutine walk
        given:
            Node tree
        returns:
            List values

        if not empty tree:
            List left  ← walk tree.left
            List right ← walk tree.right
            push values, filter not empty, left, tree.value, right

    return values

The filter function applies the Boolean subroutine to each item in a List and returns only those for which its results are TRUE.

Empty Variables

Some command and functions for dealing with empty variables.

erase

Usage:

    erase variable

Removes the contents of a variable and makes it empty.

empty

Usage:

    Boolean bool ← empty variable

Determines if a variable is empty and returns TRUE if it is, FALSE if it isn't. This is the opposite of filled.

filled

Usage:

    Boolean bool ← filled variable

Determines if a variable has content and returns TRUE if it has, FALSE if it doesn't. This is the opposite of empty.