dannyyy
dannyyy

Reputation: 149

How to split a list in c++?

Im trying to implement merge sort with an unsorted linked list but need to use the stl list in C++. I understand how to implement it with a linked list that I would make myself but am confused on how to use the stl list.

For example, how would I got about splitting up the list? Since there are no next pointers to set to null, I don't get how I go about recursively splitting the list. Any help is appreciated!

Upvotes: 2

Views: 652

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490663

The conventional approach (for C++) would be to leave the list itself intact.

Instead of splitting the list, have your code work with iterators, and to "split the list", pass a pair of iterators to only part of the list instead of the whole thing.

Upvotes: 4

Related Questions