boolean function returning true when it shouldn't C++ : <p>I have a program that searches a binary search tree using breadth first search with each type of traversal. all my functions work and run but the last traversal, postorder traversal, returns true when searching a number that is not in the tree. I have debugged the program and watched it run through the entire tree in the postorder traversal function and it never once actually returns true, but still is printing out the true output. Can anyone tell me why? </p>

<pre><code>#include &lt;queue&gt;
#include &lt;iostream&gt;
using namespace std;

struct Node
{
    int data;
    Node *left, *right;
}*root;

Node *createNode(int data)
{
    Node *Tnode = new Node;

    Tnode-&gt;left = NULL;

    Tnode-&gt;right = NULL;

    Tnode-&gt;data = data;

    return Tnode;
}

vbool breadthFirstSearch(Node *node, int item)
{
    queue&lt;Node*&gt; q;

    if(root)
    {
        q.push(root);
        while(!q.empty())
        {
            Node *d = q.front();
            q.pop();
            if(d-&gt;data == item)
                return true;
            if(d-&gt;left)
                q.push(d-&gt;left);
            if(d-&gt;right)
                q.push(d-&gt;right);

        }
    }
    return false;
}

bool inorderTraversal(Node *node, int item)
{
    if(node == NULL)
        return false;
    inorderTraversal(node-&gt;left, item);
    if(node-&gt;data == item)
        return true;
    inorderTraversal(node-&gt;right, item);
}

bool preorderTraversal(Node *node, int item)
{
    if(node == NULL)
        return false;
    if(node-&gt;data == item)
        return true;
    preorderTraversal(node-&gt;left, item);
    preorderTraversal(node-&gt;right, item);
}

bool postorderTraversal(Node *node, int item)
{
    if(node == NULL)
        return false;
    postorderTraversal(node-&gt;left, item);
    postorderTraversal(node-&gt;right, item);
    if(node-&gt;data == item)
        return true;
}

int main()
{
    root = createNode(20);
    root-&gt;left = createNode(10);
    root-&gt;left-&gt;left = createNode(5);
    root-&gt;left-&gt;right = createNode(15);
    root-&gt;right = createNode(30);
    root-&gt;right-&gt;left = createNode(25);
    root-&gt;right-&gt;right = createNode(35);

    cout&lt;&lt;"\n-----Breadth First Search Traversal-----\n";

    if(breadthFirstSearch(root, 35) == true)
    {
        cout&lt;&lt; "The item 35 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 35 is not in the tree\n";
    }
    if(breadthFirstSearch(root, 29) == true)
    {
        cout&lt;&lt; "The item 29 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 29 is not in the tree\n";
    }

    cout&lt;&lt;"\n-----Inorder Search Traversal-----\n";

    if(inorderTraversal(root, 35) == true)
    {
        cout&lt;&lt; "The item 35 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 35 is not in the tree\n";
    }
    if(inorderTraversal(root, 29) == true)
    {
        cout&lt;&lt; "The item 29 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 29 is not in the tree\n";
    }
    cout&lt;&lt;"\n-----Preorder Search Traversal-----\n";

    if(preorderTraversal(root, 35) == true)
    {
        cout&lt;&lt; "The item 35 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 35 is not in the tree\n";
    }
    if(preorderTraversal(root, 29) == true)
    {
        cout&lt;&lt; "The item 29 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 29 is not in the tree\n";
    }
    cout&lt;&lt;"\n-----Postorder Search Traversal-----\n";

    if(postorderTraversal(root, 35) == true)
    {
        cout&lt;&lt; "The item 35 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 35 is not in the tree\n";
    }
    if(postorderTraversal(root, 29) == true)
    {
        cout&lt;&lt; "The item 29 is in the tree\n";
    }
    else
    {
        cout &lt;&lt; "The item 29 is not in the tree\n";
    }
    return 0;
}
</code></pre>

<p>Each of the other traversals correctly prints out 35 is in the tree, 29 is not in the tree. Only post order prints that 29 is in the tree even though true is never returned when 29 is being checked. Im sure i am missing something small and silly but i just cannot seem to find it.</p>
