From the course: C++ Templates and the STL
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Sorting - C++ Tutorial
From the course: C++ Templates and the STL
Sorting
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
About STL algorithms1m 42s
-
(Locked)
Testing conditions2m 36s
-
(Locked)
Searching and counting4m 38s
-
(Locked)
Replacing and removing4m 14s
-
(Locked)
Modifying algorithms5m 46s
-
(Locked)
Partitions2m 52s
-
(Locked)
Sorting3m 42s
-
(Locked)
Merging sequences2m 4s
-
(Locked)
Binary searches3m 57s
-
(Locked)
-