Using a custom data structure, your operation could be done in constant time.
If you are using a linked list with an extra node that stores the max and min values in the list as well as the front and back nodes. If the largest element of S1 is less that the smallest element of S2 then all you do is link the front node of one to the back node of the other.
In reality, you would most likely use std::set and is would take (to be highly exact):
> In reality, you would most likely use std::set and is would take (to be highly exact):
> min(S1.size(), S2.size())log(max(S1.size(), S2.size())
Linear time (amortised constant time for each element), with a properly formed hint
(The new element is inserted just before the position indicated by the hint).
ie. O(N) where N is the number of elements inserted.