C++ : Binary tree - Remove children from parent vector
<p>i have this structure:</p>

<pre><code>#include &lt;stddef.h&gt;
#include &lt;vector&gt;

typedef int T;
class tree; 

class node {
    T info;
    std::vector&lt;node*&gt; children;
    friend class tree;
public:
    typedef std::vector&lt;node*&gt;::iterator iterator;
    iterator begin() {
        return children.begin();
    }
    iterator end() {
        return children.end();
    }
    T get() {
        return info;
    }
};

class tree {
    node* r;
    void del(node* v) {
        if (v == NULL) return;
        for (node::iterator it = v-&gt;begin(); it != v-&gt;end(); ++it)    
            del(*it);
        delete v;
    }
public:
    tree() : r(NULL) { }
    node* add(T info, node* parent) {
        node* v = new node;
        v-&gt;info = info;
        if (parent != NULL) parent-&gt;children.push_back(v);
        else {
            if (r != NULL) del(r);
            r = v;
        }
        return v;
    }
node* add(T info) {

        return add(info, NULL);
    }
    node* root() { return r; }
    void remove(node* v) {
        if (r == v) r = NULL;
        else { /* remove v from the list of children of its parent */ }
        del(v);
    }
};
</code></pre>

<p>I need to Complete the function remove by deleting the node v from the list of its parents. To do so efficiently, i would add to the node class a pointer to its parent and update the add function accordingly.
This is my solution
I modify the add function with:</p>

<pre><code> node* add(T info, node* parent) {
    node* v = new node;
    v-&gt;info = info;
    if (parent != NULL) {
         parent-&gt;children.push_back(v);
         v-&gt;parent=parent; }
    else {
         if (r != NULL) del(r);
         r = v;
         r-&gt;parent=null;
          }
    return v;
}
</code></pre>

<p>and i modify the remove function as:</p>

<pre><code>  void remove(node* v) {
        if (r == v) r = NULL;
        else { 
         v-&gt;parent-&gt;children.pop_back(v);  
         }
        del(v);
    }
</code></pre>

<p>Is this conceptually correct? Unfortunately the <code>pop_back method</code> of the class <code>vector</code>do not allows this kind of arguments so this return an error. 
Is this correct or should i use another implementation? </p>

<p>Sorry, i'm not so familiar with c++ . Thanks</p>