Lab 12

Here’s a definition for binary trees:

  (define-type BTree
      [leaf]
      [node (s string?)
            (l BTree?)
            (r BTree?)])

  1. Develop the function in-order, that prints the elements of a btree in-order. For example, this tree

    (yes, it should have a few more leaf nodes...)

    ...would print:

    cow

    dad

    bob

    king

    cat

  2. Develop the function pre-order, that would print:

    bob

    dad

    cow

    cat

    king

  3. Add a global box named kont that represents the "other computation".

  4. Update the in-order and pre-order procedures so that after printing a line, each one uses let/cc to grab its current continuation, then stows it in the global kont box and invokes the existing value stored in the box to allow the other computation to continue.

    The printed result should then be the interleaving of the earlier two, that is:

    cow

    bob

    dad

    dad

    bob

    cow

    king

    cat

    cat

    king

Thanks to Nicolas Artman for transcribing this lab.