I need help sorting this double linked list (C++)
<p>This is what I have so far:</p>

<pre><code>void sort(const E &amp;t)
{
  DNode&lt;E&gt; *tmp = new DNode&lt;E&gt;(t,NULL,NULL);


    if(size==0)
    {
        cout &lt;&lt; "List is empty" &lt;&lt; endl;
    }

            else if(t&lt;=head-&gt;element)
            {
                tmp-&gt;element=t;
                head-&gt;prev = tmp;
                tmp-&gt;next=head;
                head = tmp;
            }
                    else if(t&gt;=tail-&gt;element)
                    {
                        tmp-&gt;element=t;
                        tail-&gt;next = tmp;
                        tmp-&gt;prev=tail;
                        tail = tmp;
                    }

                         curr=tmp;
                         insert(t);
                         size++;
} 
</code></pre>

<p>insert() is just another function in my program:</p>

<pre><code> void insert(const E &amp;t)
{
  DNode&lt;E&gt; *tmp = new DNode&lt;E&gt;(t,NULL,NULL);
  if (size == 0)
  { curr=head=tail=tmp; }
  else 
  {
    tmp-&gt;next=curr;
    tmp-&gt;prev=curr-&gt;prev;
    if (curr-&gt;prev) curr-&gt;prev-&gt;next=tmp;
    else { head=tmp; }
    curr-&gt;prev=tmp;
    curr=tmp;
  }
  size++;
}
</code></pre>

<p>It does compile, but it doesn't give the correct results. I'm not sure what my errors are, and I would really need help.
Any help would be appreciated.</p>

<p>This is in my main program:</p>

<pre><code>  one.sort(10);
  one.sort(20);
  one.sort(30);
  one.sort(40);
  one.sort(50);
  one.sort(60);
  one.print();
  one.moveToEnd();
  one.prev(); 
  one.prev();
  one.remove();
  one.remove();
  one.print();

  cout&lt;&lt;endl;
</code></pre>

<p>I should be getting this: </p>

<p>HEAD==> 10 -> 20 -> 30 -> 40 -> 50 -> 60 &lt;==TAIL
HEAD==> 10 -> 20 -> 50 -> 60 &lt;==TAIL</p>

<p>But I get this instead: 
HEAD==> 10 -> 20 -> 20 -> 30 -> 30 -> 40 -> 40 ->  50 -> 50 -> 60 -> 60&lt; ==TAIL
HEAD==> 10 -> 20 -> 20 -> 30 -> 30 -> 40 -> 40 -> 60 -> 60 &lt;==TAIL</p>
