← Quiz: STL Algorithms: all 10 questions
Quiz: STL Algorithms · Question 4 of 10
Which sorts a vector v in DESCENDING order?
Which sorts a vector v in DESCENDING order?
- A.sort(v.begin(), v.end())
- B.sort(v.begin(), v.end(), greater<int>())
- C.reverse(v.begin(), v.end()) alone
- D.sort(v.end(), v.begin())
Answer & explanation
Correct answer: sort(v.begin(), v.end(), greater<int>())
greater<int> reverses the comparison. (Reverse alone doesn't sort.)
Can you get the rest right without peeking?
Take the timed Quiz: STL Algorithms quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →