2 ms·
> When I split linked list in two, the new list must > somehow become the owner of the newly detached elements. Yes, which is what `split_off` is already do
by kibwen 10y ago
> When I split linked list in two, the new list must
> somehow become the owner of the newly detached elements.
Yes, which is what `split_off` is already doing. It doesn't take unsafe code or breaking the "Rust memory management model" to achieve this; ownership transfer is a fundamental part of the language. The `split_at_node` function that I describe could simply copy the implementation of the existing `split_off` function while removing the part where `split_off` iterates through the list to find the node at the specified index (which is the O(n) part of the function).