[Cs3] sorting algorithms vs. list member functions
Mikhail Nesterenko
mnestere at kent.edu
Mon Oct 7 22:10:56 EDT 2024
CS3 students,
Sorting algorithms
std::sort() requires random access iterators and does not work on lists
std::unique(), std::merge() and std::reverse(), std::remove()
However,
the corresponding list member functions
sort(), unique(), merge(), reverse() and remove()
work entirely differently from the generic STL algorithms. Instead of
moving, or copying the elements, the list member functions update
_pointers_ to the elements changing the order the list elements are
linked. This may potentially be a lot more efficient if the elements
are large and copying or moving them is expensive.
Hope this makes sense.
Good luck on the exam tomorrow.
--
Mikhail
More information about the cs3
mailing list