Learn about the sorting algorithms, which include traditional sort and stable sort.
- [Instructor] The STL provides a few different options…for sorting a container.…Here I have a working copy of sort.cpp from…chapter six of the exercise files.…And, you'll notice that I have a comparison operator here…for comparing two values, and we're going to start by using…the default comparison in Sort,…and I'll be sorting the integers here.…So, I have two vectors: I have integers and I have doubles.…Integers are prime numbers under a hundred that are unsorted…and the doubles numbers we'll get to that in a little bit.…
So, when I build and run here, you'll see the Sort function…with just a range in it from the…begin and end of vector one.…It sorts these numbers with the default comparison operator.…And, if I want to use my own comparison operator,…I can say mycomp,…int, and build and run, and I get exactly the same result.…Of course, I can turn around the comparison,…make it greater than rather than less than,…and now, my vector will be sorted in the opposite order.…
So, this all works as we expect,…and I'll go ahead and put my comparison operator back.…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.