swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Queston about Binary Search Trees


From: Marcus G. Daniels
Subject: Re: Queston about Binary Search Trees
Date: 08 Nov 1998 09:41:47 -0800

>>>>> "PJ" == Paul E Johnson <address@hidden> writes:

PJ> Why would I want to add objects to a tree when the comparison
PJ> shows they are equal? Suppose we are building a tree of people and
PJ> we use their height in the comparison function, so we have -1 if a
PJ> is shorter than b, 0 if equal, and 1 a has more height than b.
PJ> You can add nodes to the tree and all is well until you have a
PJ> second person come along with exactly the same height as one of
PJ> the others.  The comparison function returns 0, that node is not
PJ> entered into the tree. This is not satisfactory if one is building
PJ> the tree to fulfill a later purpose of finding the 5 tallest
PJ> people in a group.

If you want everyone to be in the tree, change the comparision function
(the key) to look at not only the height, but also a unique 
identifier as a tiebreaker.  

                  ==================================
   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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]