Toon Moene writes:
> Richard Maine wrote:
[linked lists need pointers]
> Huh? - Perhaps I do not understand "linked lists" ? :-)
>
> TYPE LINKEDLIST
> TYPE (LINKEDLIST), ALLOCATABLE :: NEXT
> TYPE CONTENT
> blah ... blah ... blah
> END TYPE CONTENT
> END TYPE LINKEDLIST
...
Well, you *CAN* do it that way. But would you want to?
You left out all the "fun" parts. Try now doing an insertion
or deletion in the middle of such a list (or at the beginning
for that matter). Yes, its possible. But you end up copying
the whole list (or anyway the part of it after the insertion).
Insertion and deletion is to me what makes it naturally a pointer.
The fundamental propery of pointers is that they can be changed
to point at different things. When you insert in a linked list,
you want the node prior to the insertion point to now point to
your new node instead of whatever it used to point to. That
seems like a pretty good match to me.
Or try generalizing to doubly-linked lists (forward and
backward links) so that I can pass a node to a subroutine
and then have the subroutine get to the preceding node in
the list.
I'll grant its probably possible. But its trivial and "natural"
(at least it seems natural to me) with pointers.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|