im trying to store preorder tree transversal into a stack though am getting a wide array of errors: to many arguments in void print_order, to many arguments in void preorder, and push has not been declared. any help please!

void print_inorder(BST *& p, stack <int> *& s);
void printOutText(BST *& p)
{
     ofstream myfile;
     myfile.open ("example.txt");     
     stack <int> s;
     
     preorder(p, s);
     
     myfile.close();
     

}

void preorder(BST *& p, stack <int> *& s)
{       
     if (p != NULL) 
     {
        s.push(p->data);
        preorder(p->left);  // print left subtree
        preorder(p->right); // print right subtree
     }

You haven't shown us the code where the problems are occurring. It should be easy to spot a "too many arguments" type of problem. Have you included <stack> ?

That is the only reason I would say push() would not be defined. Here is an example of using stack:
http://programmingexamples.net/index.php?title=CPP/STL/Stack

David

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.