BST - find number of elements
<p>Is there a way to find the number of elements in the binary search tree?</p>

<pre><code>struct node
{
    node *p, *left, *right;
    int key;
};
</code></pre>

<p>This is my node's structure, p pointer is pointing to the parent element.</p>

<p>I need to find that number to allocate memory for searching the tree and returning an array with all elements.</p>

<p>I've came up with something like this:</p>

<pre><code>int numberOfElements(node *root, int count = 0)
{
    if(root)
    {
        numberOfElements(root-&gt;left, ++count);
        numberOfElements(root-&gt;right, ++count);
    }
    return count + 1;
}
</code></pre>

<p>But well, it shows some random results :P For "1, 2" is displays 2, for "1, 2, 3, 4, 5, 6, 7" it displays 3 etc...</p>

<p>I want to do this inside one function, that's why count is an argument here.</p>

<p>How can I do this?</p>
