Johnny Vaquiz
2005-09-30 02:59:05 UTC
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;
}
}
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;
}
}