hi guys,
can you help me with my code I have a problem with my function it is not print the number in pre-order.
please i need a quick help because i have one hour to send the assignment
my code
void preOrder(BSTNode* root)
{
stack<BSTNode*> Pre; // initialize the pre-order with the queue
Pre.push(root);
while(!Pre.empty()) // check if it is not empty
{
BSTNode *root = Pre.push();
Pre.pop();
if(root!= NULL) // check if the root not pointing to NULL
{
Pre.push(root->left);
Pre.push(root->right);
cout << root->value << " ";// print the number for pre-order
}
}
}
if(root!= NULL) // check if the root not pointing to NULL
{
Pre.push(root->right);
Pre.push(root->left);
cout << root->value << " ";// print the number for pre-order
}