I am currently working on an assignment for a comp sci class that requires me to implement a bunch of different functions with binary search trees. The current function that I am having trouble wrapping my head around goes through the tree and recursively splits it into a pointer to two separate trees. I am generally just confused on how to do this with pointers to pointers to Node objects (which is how he set up the function when he gave us the assignment)
void split(Node *T, int k, Node **L, Node **R)
{
if(T == nullptr){
}
else{
if(T->key <= k){
Node *RightL;
Node *RightR;
Node *temp = T;
split(T->right,k,&RightL,&RightR);
temp->right = nullptr;
temp->right = RightL;
R = &RightR;
L = &temp;
}
else{
Node *LeftL;
Node *LeftR;
Node *temp = T;
split(T->left,k,&LeftL,&LeftR);
temp->left = nullptr;
temp->left = LeftR;
R = &temp;
L = &LeftL;
}
}
}
As far as the logic of this, he described that if the key/value of the current tree node is less than the value given when the function is called it should take the current node along with all its left tree contents and put it into the left tree and then take the resulting left side after splitting the right branch and set it to the missing right branch of the left tree. The right branch of the split right branch is then assigned to the right tree.
How can I rewrite what I currently have to make it work?