[futurebasic] Singly Linked Lists...again

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: Chris <behmc@...>
Date: Fri, 5 Dec 1997 16:35:49 -0500
Ok, I've started to implement a generic Linked list and it's working out
pretty well (thanks to all who replied before).  The new problem I've run
into is adding an element to the top (head) of the list.  What I've been
doing is allocating the space for a new element

newElement& = FN NEWHANDLE _clear(_ListElement)

then I set the nextE& reference in newElement& to the old head& ('cause
head& pointed to the original top of the list)

newElement&..nextE& = head&

I thought that this would set the reference of nextE& to the blank initial
element that I had set up in the list.

then I set the head to the new top

head& = newElement&

I know I'm messing something up because all this does is assign the
reference of head& and newElement&..nextE& to the same chunk of memory.  I
ran with the debugger so I could use Debug II's Hex Handle variable menu
item to see what the two things pointed to.  Head should, and did, point to
the newElement&.  However, newElement& was the exact same record as
head&... the nextE& pointed to newElement&.

This is a brick wall I've run up against and for some reason the error just
isn't coming to me.

I've looked at the sample code that I've been sent and I haven't been able
to get it straight.  In Greg's code he's adding the list elements to the
tail of the list so it doesn't have to modifiy the head.

If I've left something out of my description here then just let me know.

Thanks for any help (again),