Efficient linked list in C++?

后端 未结 11 652
孤街浪徒
孤街浪徒 2021-02-02 06:36

This document says std::list is inefficient:

std::list is an extremely inefficient class that is rarely useful. It performs a heap allocation

11条回答
  •  无人及你
    2021-02-02 07:00

    I just wanted to make a small comment about your choice. I'm a huge fan of vector because of it's read speeds, and you can direct access any element, and do sorting if need be. (vector of class/struct for example).

    But anyways I digress, there's two nifty tips I wanted to disclose. With vector inserts can be expensive, so a neat trick, don't insert if you can get away with not doing it. do a normal push_back (put at the end) then swap the element with one you want.

    Same with deletes. They are expensive. So swap it with the last element, delete it.

提交回复
热议问题