I'm having a lot of trouble using vector as a private data member. I'm not sure how to reserve space for 10 elements and I tried a combination of resize and I also tried calling the vector constructor in my class's constructor but I keep getting compilation errors from the vector constructor. I want to initialize the vector with 10 elements, because I'm trying to populate a vector with the values from my binary tree.
class bst
{
public:
// constructor: initializes an empty tree
bst()
{
root = nullptr;
totalNodes = 0;
treeHeight = -1; // empty tree with no nodes has a height of -1
myVector->reserve(10);
}
private:
bst_node * root;
int totalNodes;
std::vector<T> *myVector;
int treeHeight; // height of the tree to be used later for some functions
}; // end class bst
void _to_vector(bst_node *r, std::vector<T> *vec)
{
if (r == nullptr) {
return;
}
_to_vector(r->left, vec);
vec->push_back(r->val);
_to_vector(r->right, vec);
}