1 with TEXT_IO ; use TEXT_IO ; 2 procedure MAIN is -- SAME AS BEFORE, JUST ADDED INDENTATION TO PRINTOUT 3 type NODE ; -- just introduce type name 4 type NODE_PTR is access NODE ; -- define an access type 5 -- ie the type of a pointer 6 type NODE is -- now, really define the type NODE 7 record 8 BF : INTEGER ; -- balance factor for later use 9 LEFT : NODE_PTR ; -- this records predecessor 10 RIGHT : NODE_PTR ; -- this records sucessor 11 NAME : STRING(1..2) ; -- data, the "sort" key 12 PHONE : STRING(1..2) ; -- more tag along data 13 end record ; 14 15 ROOT_PTR : NODE_PTR := new NODE'(0, null, null, "D ", "4 ") ; 16 -- build a dummy root node 17 LEFT_PTR : NODE_PTR ; 18 RIGHT_PTR : NODE_PTR ; 19 20 DEPTH : INTEGER := 1 ; -- indentation depth 21 22 procedure OUTPUT(T : NODE_PTR ) is 23 procedure INDENT is -- new procedure inside OUTPUT 24 begin 25 for I in 1..DEPTH loop 26 PUT(" ") ; 27 end loop ; 28 end INDENT ; 29 begin 30 DEPTH := DEPTH + 1 ; -- count depth "down" upon entry 31 if T /= null then 32 OUTPUT(T.LEFT) ; 33 INDENT ; PUT(T.NAME) ; PUT_LINE(T.PHONE) ; 34 OUTPUT(T.RIGHT) ; 35 end if ; 36 DEPTH := DEPTH - 1 ; -- count depth "up" upon exit 37 end OUTPUT ; 38 39 begin 40 PUT_LINE(" basic access types ") ; Same as previous page basic access types A 1 B 2 C 3 D 4 E 5 F 6 G 7