Why can std::sort NOT be used directly on a std::list?
Correct answer A. std::sort needs random-access iterators but std::list provides only bidirectional iterators
std::sort relies on jumping to arbitrary positions in constant time, so it requires random-access iterators, which vector, deque and plain arrays provide. A doubly linked list only supports stepping forwards and backwards. That is why std::list has its own member function list.sort(), a merge sort that relinks nodes instead of moving elements.
Answer checked How we write and check questions
Discussion