Binary Search Tree Output
<p>I am having trouble outputting a binary search tree.  I have to build the tree, and then place all the doubles from the tree in order into a vector, and then output that vector in order.  The problem I am having is getting it into the vector and outputting it.  When I just output the tree, everything works as it is supposed to.  The vector is supposed to get sorted and the std::vector* sort() is supposed to return a pointer to a vector.  The problem I am having is that I get a segmentation fault, and I don't know why.  Any advice would be appreciated.  Here is my code:</p>

<pre><code>#include &lt;vector&gt;

struct ordered_set {
private:
    class node {
    public:
        double val;
        node* left;
        node* right;

        node(double v, node* l, node* r): val(v), left(l), right(r) { }
    };

    node* root;
    int size;

public:
    ordered_set();
    void insert(double x);
    std::vector&lt;double&gt;* sort();
    std::vector&lt;double&gt;* order(node*);
};

#include &lt;vector&gt;
#include &lt;iostream&gt;

#include "ordered_set.hpp"

ordered_set::ordered_set()
{
    root = 0;
    size = 0;
}

void ordered_set::insert(double x)
{
    node* data = new node(x, 0, 0);
    node* parent;
    parent = 0;

    if(root == 0)
        root = data;
    else
    {
        node* curr = root;
        while (curr)
        {
            parent = curr;
            if(data-&gt;val &gt; curr-&gt;val)
                curr = curr-&gt;right;
            else
                curr = curr-&gt;left;
        }
        if(data-&gt;val &lt; parent-&gt;val)
            parent-&gt;left = data;
        else
            parent-&gt;right = data;
    }
    ++size;
}

std::vector&lt;double&gt;* ordered_set::sort()
{
    node* ndptr = root;
    return order(ndptr);
}

std::vector&lt;double&gt;* ordered_set::order(node* top)
{
    node* curr = top;
    std::vector&lt;double&gt;* set;
    std::vector&lt;double&gt;::iterator it = set-&gt;begin();

    if(curr != 0)
    {
        order(curr-&gt;left);
        set-&gt;insert(it, curr-&gt;val);
        ++it;
        order(curr-&gt;right);
    }
    else return set;
}
</code></pre>
