C++ binary search tree I am learning C++ and today I've implemented a version of the binary search tree. I would like your thoughts about it.

node.h

#pragma once

struct Node
{
   int val;
   Node *left;
   Node *right;
};


bTree.h

#include "node.h"

#pragma once

class BTree
{
private:

    Node *root;
    void addValue(int n, Node *node);
    void traverse(Node *node);
    Node* search(int n, Node *node);

public:

    BTree();

    void addValue(int n);
    void traverse();
    void search(int n);
};


bTree.cpp

#include &lt;iostream&gt;
#include "bTree.h"

BTree::BTree()
{
    root = nullptr;
}

void BTree::addValue(int n, Node *node) {
    if (n &lt; node-&gt;val)
    {
        if (node-&gt;left != nullptr)
        {
            addValue(n, node-&gt;left);
        }
        else
        {
            node-&gt;left = new Node;
            node-&gt;left-&gt;val = n;
            node-&gt;left-&gt;left = nullptr;
            node-&gt;left-&gt;right = nullptr;
        }
    }
    else if (n &gt;= node-&gt;val)
    {
        if (node-&gt;right != nullptr)
        {
            addValue(n, node-&gt;right);
        }
        else
        {
            node-&gt;right = new Node;
            node-&gt;right-&gt;val = n;
            node-&gt;right-&gt;left = nullptr;
            node-&gt;right-&gt;right = nullptr;
        }

    }
}

void BTree::traverse(Node *node) {
    if (node-&gt;left != nullptr)
        traverse(node-&gt;left);
    std::cout &lt;&lt; node-&gt;val &lt;&lt; ' ';
    if (node-&gt;right != nullptr)
        traverse(node-&gt;right);
}

Node* BTree::search(int n, Node *node) {
    if (node != nullptr)
    {
        if (node-&gt;val == n)
            return node;
        else if (n &lt; node-&gt;val)
            return search(n, node-&gt;left);
        else if (n &gt; node-&gt;val)
            return search(n, node-&gt;right);
    }
    else
        return nullptr;
}

void BTree::addValue(int n) {
    if (root == nullptr)
    {
        root = new Node;
        root-&gt;val = n;
        root-&gt;left = nullptr;
        root-&gt;right = nullptr;
    }
    else
    {
        addValue(n, root);
    }
}

void BTree::traverse() {
    if (root == nullptr)
    {
        std::cout &lt;&lt; "No nodes in the tree" &lt;&lt; std::endl;
    }
    else
    {
        traverse(root);
    }
}
void BTree::search(int n) {
    if (root == nullptr)
    {
        std::cout &lt;&lt; "No nodes in the tree" &lt;&lt; std::endl;
    }
    else
    {
        if (search(n, root))
            std::cout &lt;&lt; n &lt;&lt; " found" &lt;&lt; std::endl;
        else
            std::cout &lt;&lt; n &lt;&lt; " not found" &lt;&lt; std::endl;
    }
}


main.cpp

#include &lt;iostream&gt;
#include "bTree.h"
#include &lt;ctime&gt;

int main()
{
    srand(static_cast&lt;unsigned int&gt;(time(0)));
    rand();

    BTree bTree{};

    for (int i = 0; i &lt; 50; i++)
    {
        int n = rand() % 100;
        std::cout &lt;&lt; n  &lt;&lt; ' ';
        bTree.addValue(n);
    }

    std::cout &lt;&lt; std::endl &lt;&lt; std::endl;

    bTree.traverse();

    std::cout &lt;&lt; std::endl &lt;&lt; std::endl;

    for (int i = 0; i &lt; 10; i++)
    {
        int n = rand() % 100;
        bTree.search(n);
    }

    std::cout &lt;&lt; std::endl &lt;&lt; std::endl;

    system("pause");

    return 0;
}
Use constructors to initialize your objects.

        root = new Node;
        root-&gt;val = n;
        root-&gt;left = nullptr;
        root-&gt;right = nullptr;


This should be replaced by:

        root = new Node(n);


Design

I think you will find that your code becomes a lot simpler if you move your test for null out of the public members. Then make the test for null the first thing you do in the private member (Don't test before you call the private member test as the first action in the call). This will simplify all the situations were you currently have to test for null.

For Example:
I would write addValue like this:

void BTree::addValue(int n) {
    root = addValue(n, root);
}
Node* BTree::addValue(int n, Node* current) {
    if (current == nullptr) {
        return new Node(n);
    }
    if (n &lt; current-&gt;val) {
        current-&gt;left  = addValue(n, current-&gt;left);
    else if (n &gt; current-&gt;val) {
        current-&gt;right = addValue(n, current-&gt;right);
    }
    return current;
}