#beginc #include #include void print_int(int x) { printf("%i",x); return; } void newline() { printf("\n"); return; } #endc prog datatype tree = Leaf of int | Node of tree * tree * int dec unit print_int(int i) dec unit newline() def tree build(int depth) = if (depth=0) then Leaf(depth) else Node(build(depth-1)@new(<>),build(depth-1)@new(<>),depth) def list(int) breadth(list(tree) l1) = match l1 with Nil(tree) -> Nil(int) | l2::tail@d -> match l2 with Leaf(i) -> Nil(int) | Node(t1@d1,t2@d2,i) -> i::breadth(Snoc(t2,Snoc(t1,tail@d2)@d1))@d def unit print_list_int (list(int) l) = match l with Nil(int) -> newline() | Cons(head,tail@d) -> (print_int(head); print_list_int(tail)) def int main() = let d = 10 in let t = build(d) and n = Nil(tree) in let b = breadth( t::n@new(<>) ) in (print_list_int(b); 1) end