Sorting an array using a Binary Search Tree with C++ Given an array of integer (all different from each other), this program creates a BST with the array elements in order to sort them and put them back into the array, using the BST properties.

#include&lt;iostream&gt;
using namespace std;

struct Node
{
    int label;
    Node* left;
    Node* right;

    ~Node() {
      delete left;
      delete right;
      }
};


void insertSearchNode(Node* &amp;tree, int x)       //insert integer x into the BST
{
    if(!tree){
        tree = new Node;
        tree-&gt;label = x;
        tree-&gt;right = NULL;
        tree-&gt;left = NULL;
        return;
    }
    if(x &lt; tree-&gt;label) insertSearchNode(tree-&gt;left, x);
    if(x &gt; tree-&gt;label) insertSearchNode(tree-&gt;right, x);
    return;
}

void insertArrayTree(int arr[], int n, Node* &amp;tree)     //insert the array integer into the nodes label of BST
{
    for(int i=0; i&lt;n; i++){
        insertSearchNode(tree, arr[i]);
    }
    return;
}

int insertIntoArray(int arr[], Node* &amp;tree, int i)      //insert into the array the node label touched during an inorder tree traversal
{
    if(!tree) return i;
    i = insertIntoArray(arr, tree-&gt;left, i);
    arr[i] = tree-&gt;label;
    i++;
    i = insertIntoArray(arr, tree-&gt;right, i);
    return i;

}

int main()
{
    Node* maintree;
    maintree = NULL;
    int num = 7;
    int arr[num] = {120, 30, 115, 40, 50, 100, 70};
    insertArrayTree(arr, num, maintree);      //insert elements into BST
    insertIntoArray(arr, maintree, 0);        //modify array sorting his elements using the BST

    for(int y=0; y&lt;num; y++) cout&lt;&lt; arr[y] &lt;&lt; ' ';

    return 0;
}


Output:

30 40 50 70 100 115 120


Any advice is welcome.
Your code is readable and easy to understand. Said that I would like to make you think about how you handle the operations in your BSTree.

You are building the functions alone, and what that causes is to manually manage these functions and compromise the structure of your tree if accidentally you write something wrong. 

You should opt for an Internal management rather than external one. For example:

struct BinaryNode
{
    int label_;
    Node* left_;
    Node* right_;

    //having constructors makes you write less code

    BinaryNode(Node *left, const int &amp;label, Node *right) : 
        label_(label), left_(left), right_(right)
    {
    }

    //const [datatype]&amp; 
    //means to not copy the value of the parameter
    BinaryNode(const int &amp;label) :
    //nullptr is typesafe use it instead of NULL which is a macro
        label_(label), left_(nullptr), right_(nullptr)
    {
    }

    ~BinaryNode() {
        delete left_;
        delete right_;
    }
};

class BinarySearchTree
{
private:
    BinaryNode *root_;

protected://if some derived class is needed (as an AVLTree)
    //Google about virtual functions for abstract classes (pure virtual too)
    virtual void Insert(const int &amp;x, Node *node)
    {
        if (x &lt; node-&gt;label_)
            if (node-&gt;left_ == nullptr)
                node-&gt;left_ = new BinaryNode(t);
            else Insert(t, node-&gt;left_);
        else if (x &gt; node-&gt;label_)
            if (node-&gt;right_ == nullptr)
                node-&gt;right_ = new BinaryNode(t);

        //If x is in the tree it does not include x again
    }

public:
    virtual void Insert(const int &amp;x)
    {
        Insert(x, this-&gt;root_);
    }
};


Don't misunderstand me, Your code is useful and is pretty (is something good to read). But, manage things externally can be messy.

Also, I recommend you to read the Google C++ Code Style

Hope it helped.

Edit: What does const int&amp; x means?

const int&amp; x is a constant reference to a value of type int so, when you use it, your function does not copy the sent value, instead it "sees where the value is allocated" takes it in account and then starts the procedure you describe within the function, additionally you cannot modify that value (because it's constant [const])

the main difference is with const [datatype]&amp; you save space. With [datatype] [paramName] you Copy the value which implies allocate the copied value.

If you feel lost in some part read it slowly it has many concepts, and remember practice makes this make sense.