I'm trying to put all the elements from a binary search tree into a vector, in order. Here is the function:
void inOrder(std::vector <double> & v) {
TreeNode **tree = &root;
while (tree) {
std::cout << "Arranging in order." << std::endl;
if ((*tree)->value) {
tree = &(*tree)->left;
std::cout << tree << std::endl;
v.push_back((*tree)->value);
}
else {
tree = &(*tree)->right;
std::cout << tree << std::endl;
v.push_back((*tree)->value);
}
}
}
};
I'm unable to get the values to push into the vector. Any ideas as to how I can accomplish this?
Aucun commentaire:
Enregistrer un commentaire