{produces a dictionary using a BST} {include file for trees} function subtree( item : char ) : tree; {produces a subtree} var t : tree; begin new( t); t^.left := nil; t^.right := nil; t^.info := item; subtree := t end; procedure left_tree( p : tree; item : char ); {pre : p points to a tree post : left child of p created and contains item} begin if p = nil then writeln('Trying to dereference nil') else if p^.left <> nil then writeln('p^.left already assigned') else p^.left := subtree( item) end; procedure right_tree( p : tree; item : char ); {pre : p points to a tree post : right child of p created and contains item} begin if p = nil then writeln('Trying to dereference nil') else if p^.right <> nil then writeln('p^.right already assigned') else p^.right := subtree( item) end; procedure infix( t : tree ); {pre : t is a pointer to a tree post : tree has been traversed inorder} begin if t <> nil then begin infix( t^.left ); write( t^.info : 4); infix( t^.right ) end end; FUNCTION Height(T : tree) : integer; FUNCTION Max(A, B:integer) : integer; BEGIN IF A > B THEN Max:= A ELSE Max:= B END (* Max *); BEGIN (* Height *) IF T = NIL THEN Height:= -1 ELSE Height:= 1 + Max(Height(T^.Left), Height(T^.Right)) END (* Height *); procedure insert( letter : char; var t : tree); {pre : t points to a BST or nil pointer. post : letter inserted in a new node st the tree is still a BST} begin if t = nil then t := subtree( letter ) else if letter < t^.info then insert( letter, t^.left ) else insert( letter, t^.right ) end; procedure binary_tree( var root : tree); {Creates a BST} var letter : char; begin root := nil; writeln('Type your letters.'); while not eoln do begin read( letter ); insert( letter, root) end; readln; writeln end;