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.
Merging sequences - C++ Tutorial
From the course: C++ Templates and the STL
Merging sequences
- [Instructor] The merge function will merge two sorted sequences into one. Here I have a working copy of merge.cpp from chapter six of the exercise files. And you'll notice I have a comparison operator that's a reverse comparison operator you notice it's a greater than. And I have two vectors both of them unsorted and they're both parts of my prime number sequence. And then I have a vector three which is the size of both the vectors added together. And that is not initialized. And so first I sort the two vectors and then I merge them using the merge function which begins with the range of one of the ranges to merge the second range to merge and then the target beginning. And so when I build and run you notice that I've got my two unsorted sequences. Here they are after they're sorted. And here they are merged all into one nice sorted sequence. So even though these are not sequential. In other words, there's numbers between 11 and 17. And 17 and 37 there's several of the them all that…
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)
-