This a const member function, which allow me to get the minimum node of the tree:
BinarySearthTree* BinarySearchTree::min() const
{
// Return the minimum node (left-most node) value of the tree
BinarySearchTree * next = (BinarySearchTree *) this;
for (next ; next != NULL; next = next->pLeft)
if (next->pLeft == NULL)
return next;
}
I have to cast down the const-ness of ‘this’ pointer when assigning it to ‘next’, but this actually rises the potential that I may modify the value of what ‘this’ points to? Rather than always remind myself not to modify whatever ‘next’ points to, is there a way to prevent it happening by a better designing of the function?
Make
nextconst: