Lists
std::list
is a doubled linked list. std::list
needs the header <list>
.
Although it has a similar interface to std::vector
or std::deque
, std::list
is quite different to both of them. That’s due to its structure.
std::list
makes the following points unique:
- It supports no random access.
- The access of an arbitrary element is slow because you have to iterate in the worst case through the whole list.
- To add or remove an element is fast, if the iterator points to the right place.
- If you add or remove an element, the iterator keeps valid.
Because of its special structure, std::list
has a few special methods.
Method | Description |
---|---|
lis.merge(c) |
Merges the sorted list c into the sorted list lis , so that lis keeps sorted. |
lis.merge(c, op) |
Merges the sorted list c into the sorted list lis , so that lis keeps sorted. Uses op as sorting criteria. | ...