Flattening Binary Tree in Java


public static Cons flattenbt (Object tree) {
    return flattenbtb(tree, null); }

public static Cons flattenbtb (Object tree,
                               Cons result) {
 if ( consp(tree) )
    return flattenbtb( lhs((Cons) tree),
                       cons( op((Cons) tree),
                             flattenbtb(
                               rhs((Cons) tree),
                               result)));
    return ( tree == null ) ? result
        : cons(tree, result); }


btr = (cat (bat ape bee)
           (elf dog fox))

flatten = (ape bat bee cat dog elf fox)

Contents    Page-10    Prev    Next    Page+10    Index