[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in Linked Lists?
From: |
Kevin Crowston |
Subject: |
Bug in Linked Lists? |
Date: |
Sat, 28 Jun 1997 14:23:36 -0400 |
I think I have found a bug in the List type collections. I have a list of
numbers, and am trying to delete duplicates. Here's a code fragment:
[point setLoc: Start] ;
next = (int)[point next] ;
while ( [point getLoc] == Member ) {
if ( nextVect[next] == 0 )
nextVect[next] = -1 ;
else
[point remove] ;
next = (int)[point next] ;
}
(point is a previously created ListIndex, i.e., point = [list begin:...] )
The nextVect[next] is used to keep track of which elements I've already
seen and is initially all 0's (I created the array for use in the next
step, so I figured I'd just reuse it here).
I'm using the [point getLoc] == Member construction because the list
contains integers, including 0 (meaning that nil is a perfectly acceptable
return value).
Okay--without looking, can you figure out what the fragment leaves in the list?
The bug is that the list ends up empty. Apparently when I remove the last
item in the list, the next next puts me back to the beginning--so I go
through the list a second time and this time delete everything, thinking
it's a repeat.
The documentation says that removing the last element leaves you at End,
but in fact it leaves you with [point getLoc] == "Removed". Doing a next
from this Removed node seems to take you to the front of the list.
Kevin
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================
- Bug in Linked Lists?,
Kevin Crowston <=