I have an AVL tree (I will not post all of the code because it wouldn't make sense), and I want to use a recursive function to delete it. The code looks something like this:
template <typename T>
struct AVL
{
Nod<T>* root;
....
void clear();
....
};
template<typename T>
inline void AVL<T>::clear()
{
....
if (root == nullptr)
{
return;
}
clear(root->left); //I can't do this because clear doesn't take parameters
clear(root->right);
....
}
In order to delete my nodes I want to recursively call this function, without taking parameters, it has to start from the root inside that struct everytime. But if I define the function without having parameters, I won't be able to call clear(root->left).
So, my question is:
how can I recursively call this function starting from the root field?