Re: traverse linked list (Fortran 90)
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: traverse linked list (Fortran 90)         

Group: comp.lang.fortran · Group Profile
Author: Ron Ford
Date: Sep 17, 2008 01:14

On Tue, 16 Sep 2008 11:30:59 -0700 (PDT), e p chandler posted:
> See http://www.pcc.qub.ac.uk/tec/courses/f77tof90/stu-notes/f90studentMIF_6.html
> for code which creates, traverses and destroys a linked list. Note
> that this is a stack - last in - first out.
>
> I found the code a bit quirky and decided to write my own so that the
> list would be traversed in the order in which items were entered. So I
> sat down and wrote out the following on a legal pad. It compiled and
> ran on the first try!
>
> program linked_list
> implicit none
>
> type node
> integer :: i
> type(node), pointer :: p
> end type node
>
> type(node), pointer :: h, t, c
>
> integer :: i
>
> nullify(h)
>
> do
> read *, i
> if ( i == 0 ) exit
>
> allocate(c)
> c%%i = i
> nullify(c%%p)
>
> if ( .not. associated(h) ) then
> h => c
> else
> t%%p => c
> end if
>
> t => c
> end do
>
> do
> c => h
> if ( .not. associated(c) ) then
> exit
> else
> print *, c%%i
> h => c%%p
> deallocate(c)
> end if
> end do
>
> end program linked_list
>
> I acutally understand what this code does! The only subtle part is
>
> t%%p => c
>
> --- If the list is NOT empty, add the newly created node onto the
> chain.
>
> -- e

It runs but has a runtime if I enter an alphabetic character.

If I enter numbers, its appetite seems infinite.

I'm given to understand that data structures on Turing-complete machines
are somehow all the same. Glen mentioned that the directory
structure--folders--for the original apples was flat, as opposed to the
tree I think of when I think of a directory. I thought that they may have
achieved that through a linked list, but I was guessing.

How does one observe the intended behavior of this list?
--
Nevertheless, it is even harder for the average ape to believe that he has
descended from man.
H. L. Mencken
no comments
diggit! del.icio.us! reddit!