Non-recursive add function in a binary tree using c++
I am writing an Add function to add nodes to a binary tree non recursively. I have run into the problem of only being able to produce one level deep binary tree. I debugged it and I know where the problem is but can't figure out how to fix it. Maybe fresh pair of eyes will see something i dont... The problem is that my temp node is being reset to the root value every new function call and hence, adding nodes linearly. Anyways, here is the function: void BinaryTreeNonRec::add(int num){ treeNode *temp, *parent; if (root==NULL) { root = new treeNode; root->data=num; root->left=0; root->right=0;