简体   繁体   English

如何在C ++中拆分列表?

[英]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++. 我试图用未排序的链表实现合并排序,但需要在C ++中使用stl列表。 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. 我知道如何使用我自己创建的链接列表来实现它,但对如何使用stl列表感到困惑。

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. 由于没有下一个指针设置为null,所以我不知道如何递归拆分列表。 Any help is appreciated! 任何帮助表示赞赏!

The conventional approach (for C++) would be to leave the list itself intact. (对于C ++)常规方法是保留列表本身不变。

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. 不用拆分列表,而是让代码与迭代器一起工作,并“拆分列表”,将一对迭代器仅传递给列表的一部分而不是整个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM