I am at the beginner level with pointers & targets and linked lists. I am working my way through Dr. Tanja van Mourik’s 2005 Fortran 90/95 tutorial. But I also use Silverfrost’s Fortran 95 tutorial however it is less useful because it somewhat assumes one already knows a lot of the material. With this preamble, I am trying to confirm here that I correctly understand how the first link is established in a linked list.
nullify (first) nullify (current) ! read in a number, until 0 is entered do read*, number if (number == 0) then exit end if allocate (current) ! create new link current%i = number current%next ⇒ first ! point to previous link first ⇒ current ! update head pointer end do
The do loop is used to create the links. Before the first loop, pointers first & current are nullified. Thus, they are both disassociated. The first loop is entered and reads in an INTEGER to number. Checks to see if number=0 to exit. If not, pointer current is allocated. Hence current is now associated with memory. The data item current%i is next equated to number.
On the next line, the pointer next is pointed to pointer first in the statement current%next ⇒ first. first at this time is disassociated. It appears this also results in current%next being dissociated?
On the next line, pointer first is pointed to pointer current. Thus, pointer first is now associated. However, pointer current%next does NOT update to associated?
Here is my issue and question. In all the prior tutorial discussions of pointers & targets and variables once the pointer – target relationship is established, a change of one, changes the other. They update. Does this only apply to variables? In the case of pointers and the attribute associated/disassociated, and a same pointer – target relationship, the associated/disassociated attribute does NOT update? I have not found any discussion of this nuance in a tutorial thus far.
If this occurs then the pointer of this link remains disassociated and thus identifies it as the last link of a linked list.