module BinaryTreeOutput;
public BinaryTreeOutput;
    procedure Infix(NodeIndex : Subscr);
    procedure Prefix(NodeIndex : Subscr);
    procedure Postfix(NodeIndex : Subscr);
public BinaryTreeMain;
    const MaxNumNodes = 20;

    type Subscr = 0..MaxNumNodes;
         Node = record
                   Symbol : char;
                   Left : Subscr;
                   Right : Subscr
                   end;
         Tree = array[Subscr] of Node;

    var NodeCharacter : char;
        NodeIndex : integer;
        ExpressionTree : Tree;

private BinaryTreeOutput;

(* -------------------------------------------------- *)
procedure Infix(NodeIndex : Subscr); (* write out the
       tree in infix notation *)
begin
    with ExpressionTree[NodeIndex] do 
        if Left <> 0 then begin
            write('(' : 1);                      
            Infix(Left);
            write(Symbol : 2);
            Infix(Right);
            write(')' : 1)
            end (* if *)
        else write(Symbol : 2)
end; (* Infix *)

(* -------------------------------------------------- *)
procedure Prefix(NodeIndex : Subscr); (* write out the
       tree in prefix notation *)
begin
    with ExpressionTree[NodeIndex] do 
        if Left <> 0 then begin
            write(Symbol : 2);
            Prefix(Left); 
            Prefix(Right) 
            end   (* if *)
        else write(Symbol : 2)
end; (* Prefix *)

(* -------------------------------------------------- *)
procedure Postfix(NodeIndex : Subscr); (* write out the
       tree in postfix notation *)
begin 
    with ExpressionTree[NodeIndex] do 
        if Left <> 0 then begin
            Postfix(Left);
            Postfix(Right); 
            write(Symbol : 2)
            end (* if *)                                 
        else write(Symbol : 2)
end; (* Postfix *)
.