with TEXT_IO ; use TEXT_IO ; procedure TACCESS1 is -- A SMALL SAMPLE TO INTRODUCE ACCESS TYPES type NODE ; -- just introduce type name type NODE_PTR is access NODE ; -- define an access type -- ie the type of a pointer 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 ; -- just some scratch objects RIGHT_PTR : NODE_PTR ; procedure OUTPUT(T : NODE_PTR ) is -- recursive procedure to walk tree begin if T /= null then OUTPUT(T.LEFT) ; PUT(T.NAME) ; PUT_LINE(T.PHONE) ; OUTPUT(T.RIGHT) ; end if ; end OUTPUT ; begin PUT_LINE(" basic access types ") ; -- build a tree manually for testing -- -- D 4 -- / \ -- B 2 F 6 first tier -- / \ / \ -- A 1 C 3 E 5 G 7 second tier -- -- 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) ; -- print the tree end TACCESS1 ;