with TEXT_IO ; use TEXT_IO ; procedure TACCESS2 is -- SAME AS BEFORE, JUST ADDED INDENTATION TO PRINTOUT type NODE ; -- just introduce type name type NODE_PTR is access NODE ; -- define an access type type NODE is -- now, really define the type NODE record BF : INTEGER ; -- balance factor for later use LEFT : NODE_PTR ; -- this records predecessor RIGHT : NODE_PTR ; -- this records sucessor NAME : STRING(1..2) ; -- data, the "sort" key PHONE : STRING(1..2) ; -- more tag along data end record ; ROOT_PTR : NODE_PTR := new NODE'(0, null, null, "D ", "4 ") ; -- build a dummy root node LEFT_PTR : NODE_PTR ; RIGHT_PTR : NODE_PTR ; DEPTH : INTEGER := 1 ; -- indentation depth procedure OUTPUT(T : NODE_PTR ) is procedure INDENT is -- new procedure in OUTPUT begin for I in 1..DEPTH loop PUT(" ") ; end loop ; end INDENT ; begin DEPTH := DEPTH + 1 ; -- count depth "down" upon entry if T /= null then OUTPUT(T.LEFT) ; INDENT ; PUT(T.NAME) ; PUT_LINE(T.PHONE) ; OUTPUT(T.RIGHT) ; end if ; DEPTH := DEPTH - 1 ; -- count depth "up" upon exit end OUTPUT ; begin PUT_LINE(" basic access types ") ; -- build a tree manually for testing -- first tier LEFT_PTR := new NODE'(0, null, null, "B ", "2 ") ; ROOT_PTR.LEFT := LEFT_PTR ; RIGHT_PTR := new NODE'(0, null, null, "F ", "6 ") ; ROOT_PTR.RIGHT := RIGHT_PTR ; -- second tier LEFT_PTR.LEFT := new NODE'(0, null, null, "A ", "1 ") ; LEFT_PTR.RIGHT := new NODE'(0, null, null, "C ", "3 ") ; RIGHT_PTR.LEFT := new NODE'(0, null, null, "E ", "5 ") ; RIGHT_PTR.RIGHT := new NODE'(0, null, null, "G ", "7 ") ; OUTPUT(ROOT_PTR) ; end TACCESS2 ; -- Output from execution: -- basic access types -- A 1 -- B 2 -- C 3 -- D 4 -- E 5 -- F 6 -- G 7