Assignment Operator for Doubly Linked List in C++
<p>I'm having trouble wrapping my head around the concept of an assignment operator, or at least creating them successfully.</p>

<p>Copy Constructors aren't an issue for me; here is mine that its working:</p>

<pre><code>//copy constructor
Set::Set(const Set &amp;rhs){
    _head = rhs._head;
    _tail = rhs._tail;

    //null, basically this object is 0
    if(rhs._head == NULL){
        _head = NULL;
        _tail = NULL;
        _size = 0;
    }else{
        _head = new Elem(*rhs._head);
        _tail = new Elem(*rhs._tail);
        _size = rhs._size;

        Elem *prev = NULL;
        Elem *curr = _head;
        Elem *otherCurr = rhs._head;
        int counter = 0;
        while(otherCurr-&gt;next != NULL){
            curr-&gt;next = new Elem(*otherCurr-&gt;next);
            curr-&gt;next-&gt;prev = curr;


            curr = curr-&gt;next;
            otherCurr = otherCurr-&gt;next;
        }

        //now that we are done lets setup the tail
        _tail-&gt;prev = curr;
        curr-&gt;next = _tail;

    }

}
</code></pre>

<p>I was reading example code, and saw some people used the <code>#include &lt;algorithm&gt;</code> library to implement it. I tried that instead, however does not seem to work at all.</p>

<pre><code>//assignment operator
Set&amp; Set::operator=(const Set &amp;rhs){
    Set temp(rhs);
       std::swap(temp._head,_head);
       std::swap(temp._tail, _tail);
       return *this;

}
</code></pre>

<p>This above code however does not work correctly. Really struggling to grasp the concept of how assignment operators are made. I figured it would basically work the same as you want to copy values from one into another. But evidently not. If anyone could advise me on how to get that working it would be great.</p>

<p>Just some more general info on my class, there is <code>a _head</code> and <code>a _tail</code> that points to the start and end of the list. Dummy Elements.</p>

<p>Here is how the object is structured:</p>

<pre><code>  struct Elem {
        ELEMENT_TYPE info;
        Elem *prev, *next;
    };
    Elem *_head, *_tail;
    int _size;
</code></pre>