Not sure how to call a function with parameters in a function with no parameters

I'm writing a binary search tree project for school, and we have a "clear()" function that is supposed to help the destructor clear dynamic memory.

We've been instructed to use a helper function for clear() if we want to call it recursively. clear() does not have any parameters, so I made a helper that does - but now I'm not sure how to call it from clear to make it recursive - since it has no parameters. I would appreciate any help, thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 //Helper for clear
void Tree:clearTreeHelper(DNode* &node){
    if(node == NULL) return;

        clearTreeHelper(node->left);
        clearTreeHelper(node->right);
        delete node; 

    node = nullptr; 
    }
}

/**
 * Helper for the destructor to clear dynamic memory.
 */
void Tree::clear() {

}
You just call the helper from clear() with the root: clearTreeHelper(root);
Note that the helper should be static and private.
Last edited on
Topic archived. No new replies allowed.