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

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…

Contents