What is the time complexity of this function?
<p>I would like to ask about the time complexity of my function. Below is my function written in C++.</p>

<pre><code>void List::swap(List&amp; other)
{
     List temp;
     Iterator r = begin();
     Iterator i = other.begin();

     while(!i.equals(other.end()))
     {
         temp.push_back(i.position-&gt;data);
         i = other.erase(i);
     }

     while(!r.equals(end()))
     {
         other.push_back(r.position-&gt;data);
         r = erase(r);
     }

     r = temp.begin();
     for(r; !r.equals(temp.end()); r.next())
     {
         push_back(r.position-&gt;data);
     }
}
</code></pre>

<p>The function purpose is swapping elements of two linked lists. The exercise requires this function to be executed in O(1) time. Because I used 3 loops, I wasn't sure how exactly to count the time complexity for mine function. </p>
