I'm trying to write a simple linked list code in Fortran90 and I think
I have it working except I don't seem to be able to deallocate it.
If I print out the contents of the list after I try to deallocate it,
I still get the same numbers back as I originally put in.
I'm completely new to linked lists, so I'm probably making some simple
logic error that I will be glad to have pointed out to me.
Here's my test code (below). I'm running v7.3 of the SGI F90 compiler.
The "sum" statement gives me 55 both times, before and after the
deallocate.
Catherine
--
------------------------------------------------------------------
Catherine Moroney ph: (520) 626-5123
Institute of Atmospheric Physics fax: (520) 621-6833
University of Arizona [log in to unmask]
P.O. Box 210081, Room 542
(1118 East 4th Street)
Tucson, AZ 85721-0081
> PROGRAM LIST
>
> IMPLICIT NONE
>
> TYPE LLIST
> INTEGER :: I
> TYPE (LLIST), POINTER :: NEXT
> END TYPE LLIST
>
> TYPE (LLIST), POINTER :: BEGIN,ILIST,TMP
> INTEGER :: I,ISUM
>
>
> allocate(begin)
> ilist => begin
> nullify(ilist%next)
>
>! POPULATE LIST
>
> do i=1,10
> ilist%i = i
> allocate( ilist%next )
> ilist => ilist%next
> end do
> nullify(ilist%next)
>
>! SUM ELEMENTS IN LIST, SUM SHOULD BE 55.
>
> isum = 0
> ilist => begin
> do while (associated(ilist))
> isum = isum + ilist%i
> ilist => ilist%next
> end do
> write(*,*) 'sum of elements = ',isum
>
>! DEALLOCATE LIST ONE ELEMENT AT A TIME
>
> ilist => begin
> do while (associated(ilist%next))
> tmp => ilist%next
> write(*,*) 'deallocating element = ',ilist%i
> deallocate(ilist)
> ilist => tmp
> end do
>
>! CHECK FOR STATUS OF LIST BY SUMMING ELEMENTS AGAIN
>
> isum = 0
> ilist => begin
> do while (associated(ilist))
> isum = isum + ilist%i
> ilist => ilist%next
> end do
> write(*,*) 'sum of elements = ',isum
>
>STOP
>END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|