with ada.text_io; with ada.integer_text_io; procedure testAccessExample is -- this program demonstrates the creation and use of pointer variables -- it also demonstrates the creation of a 2 element linked list -- it then shows the list with a third element inserted at the head of the list. type cell; -- announcement that there will be a cell type type link is access cell; -- I will have something that points to a cell type cell is -- defines a heterogeneous type known as a record -- which contains the previously defined link -- note that we have a circular definition record value : integer; next : link; end record; head : link; -- declaration of three pointers (links) current : link; newLink : link; begin -- initialize the first cell newLink := new cell; newLink.next := null; -- make the next field in the cell being pointed to NULL newLink.value := 37; -- make the value field in the cell being pointed to 37 head := newLink; -- make head point to created cell(i.e. tocell with 37) -- create another cell newLink := new cell; newLink.value := 27; -- put a value in the new link -- connect the two cells head.next := newLink; -- add the 2nd one to the end -- print the two element list with a label ada.text_io.put (" Here's the two element list "); current := head; while current /= null loop ada.integer_text_io.put (current.value); current := current.next; end loop; ada.text_io.new_line; -- create a third cell newLink := new cell; newLink.value := 4; -- insert the new node at the head of the list newLink.next := head; head := newLink; -- print the list again with a label ada.text_io.put (" Here's the list with the newest cell at the head "); -- another way to chain through the list current := head; -- set an extra pointer to move through the list ada.integer_text_io.put (current.value); while current.next /= null loop current:= current.next; ada.integer_text_io.put (current.value); end loop; end testAccessExample;