im trying to write the post order print out of a preorder binary tree reading into a text file though everything i have attempted to do so far as resulted in an error.
ive tried reading the preorder into stacks, queues, arrays, and the best ive been able to come up with is errors or only the first element of the BST being added.
does anyone have any ideas how to implement this?
void printOutText(BST *p)
{
ofstream myfile;
myfile.open ("example.txt");
preorder(p);
myfile.close();
}
void preorder(BST *p)
{
if (p != NULL)
{
cout << p -> data;
preorder(p->left); // print left subtree
preorder(p->right); // print right subtree
}
}