Get pointer to node in std::list or std::forward_list

后端 未结 5 536
猫巷女王i
猫巷女王i 2021-01-14 10:41

I am planning to use std::list in my code, I decided not to use std::forward_list, because for deletions (I figured) the whole list will have to traversed, O(N) complexity f

5条回答
  •  执笔经年
    2021-01-14 11:02

    is there a way I can get a pointer to the node in the list

    Yes, in your particular implementation.

    No, in a standard-compliant way.

    If you look at the std::list documentation, there is not a single word about a node. While it is hard to imagine a different way to implement the std::list other than using a doubly linked list, there is nothing that prevents it.

    You should almost never come into any contact with undocumented internals of libraries.

提交回复
热议问题