Discussion:
WeightedNode Class...
(too old to reply)
Johnny Vaquiz
2005-09-30 02:59:05 UTC
Permalink
So this it he compareTo method in the Weighted Node class. Since
isLeaf() always returns false isn't this method always going to return 0
if the weights of the nodes are the same?

public int compareTo( Object test )
{
if ( node_weight < ((WeightedNode) test).weight() )
return -1;
else if ( node_weight > ((WeightedNode) test).weight() )
return 1;
else
{
if ( isLeaf() && !((WeightedNode) test).isLeaf() ) return -1;
if ( !isLeaf() && ((WeightedNode) test).isLeaf() )
return 1;
return 0;
}
}
Jack
2005-09-30 03:16:26 UTC
Permalink
Nah, if you compare a WeightedNode to a WeightedLeaf, the method isLeaf() is
overridden in the WeightedLeaf() class. So, it's possible to compare a node
and a leaf (cause WeightedLeaf inherits from Node) and get a non-zero
answer.

I think anyhow.. :D

Loading...