← Quiz: Iterators in C++: all 10 questions
Quiz: Iterators in C++ · Question 4 of 10
Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?
Why does sort(myList.begin(), myList.end()) fail to compile for a std::list?
- A.list elements cannot be compared
- B.sort needs random-access iterators, but list iterators are only bidirectional
- C.list has no begin() function
- D.sort only works on arrays
Answer & explanation
Correct answer: sort needs random-access iterators, but list iterators are only bidirectional
Use the member function myList.sort() for lists.
Can you get the rest right without peeking?
Take the timed Quiz: Iterators in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →