I improved and simplified the body of the 'getNearestNeighbour()' member function:
Code: Select all
Function Tree##nameTree.getNearestNeighbour(value As datatype) As datatype
Static As Tree##nameTree Ptr p
If @This = 0 Then
Dim As Tree##nameTree Ptr p0
p0 = p
p = 0
Return p0->value
Else
If p <> 0 Then
If Abs(value - This.value) < Abs(value - p->value) Then
p = @This
End If
Else
p = @This
End If
If (value < This.value) Then
Return This.nodeLeft->getNearestNeighbour(value)
Else
Return This.nodeRight->getNearestNeighbour(value)
End If
End If
End Function
2)
Removed 2 unnecessary lines in Destructor:
Code: Select all
Destructor Tree##nameTree()
If This.nodeLeft <> 0 Then
Delete This.nodeLeft
End If
If This.nodeRight <> 0 Then
Delete This.nodeRight
End If
End Destructor
Both member procedures to be updated in 'btree.bi'.