[Cs3] Exam review question
Mikhail Nesterenko
mikhail at cs.kent.edu
Mon Oct 2 13:14:25 EDT 2023
>
> I have been working on the example midterm and I was looking through the slides and my notes to understand something. I am struggling to understand why splice() is used only for lists and not any other sequential container.
>
> Looking through the slides there is no information on it other than saying that splice is a specialized method for lists. Does that mean that the reason why splice is used only for lists and not any other sequential container is just because splice is a specialized method for a list?
Splice essentially takes one list and inserts in in the other by
re-arranging list pointers. Assume you have two lists: X and Y with
three elements each and iterator IT pointing to the middle of Y.
Like so:
X ---------------------------
| |
-----> X1 <--> X2 <---> X3<-
Y
|
-------> Y1 <--> Y2 <---> Y3
^
|
IT
Y.splice(IT, Y, Y.begin(), Y.end():
Will rearrange the picture as follows:
X1 <--> X2 <--> X3
^ ^
| |
Y ------------- |
| | |
-------> Y1 <--> Y2<- ->Y3
^
|
IT
Thanks,
--
Mikhail
More information about the cs3
mailing list