[cs13001] sorting vector in reverse

Dianne Foreback dforebac at kent.edu
Wed Nov 5 17:09:37 EST 2014


Hello CSI Class:

Per the question posed in today's lecture regarding sorting a vector in
descending order with the sort function.  Yes, this can be accomplished.
two ways are given below where v is a vector.

sort(v.rbegin(), v.rend());  //sorts in reverse order with reverse
iterators (See section 18.1 of your book).

sort(v.begin(), v.end(), std::greater<int>()); // #include <functional> .
Learn more about this by taking the CS3 class.

Kind Regards,
Dianne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://listmail.cs.kent.edu/pipermail/cs13001/attachments/20141105/8678f69c/attachment.html 


More information about the cs13001 mailing list