> Date: Wed, 9 Aug 2000 14:29:35 -0700 (PDT)
> Subject: deallocating linked lists (help)
> From: Catherine Moroney <[log in to unmask]>
> To: [log in to unmask]
> Reply-to: Catherine Moroney <[log in to unmask]>
> 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.
You don't say whether a message stating that an element was
deallocated, was printed.
However, if you look carefully at the code for de-allocating
elements, it does not seem to be changing any pointers in the list,
hence the list is unchanged.
Which brings me back to my question implied earlier:
which elements in the list do you want to delete, and in what order?
If you successfully address this question, then
you'll succeed in deleting an element.
P.S. Have you considered deleting just one element first,
without using a loop?
> 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]
>
> > 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|