create the "merge" function?

hi,
I tried to make a generic implementation in C ++, but I don't know how to create the "merge" function.
someone to show me the program of the "Merge" function please
thank you in advance :)

1
2
3
4
5
6
7
8
9
10
11
12
13
  //Merge sort implementation
  //-------------------------
#include "/home/src/prog.hpp"
template<typename T>
void mergesort(vector<T> &t) {
    if(t.size() > 1) {
      vector<T> t1(t.begin(), t.begin()+t.size()/2);
      vector<T> t2(t.begin()+t.size()/2, t.end());
      merge sort(t1); merge sort(t2);
      merge(t1, t2, t);
    }
}
Last edited on
Please, do not double-post. Your other thread: <removed-url>
(You can move your threads from one forum to an another yourself.)
Edit: User removed the other thread.


What is the problem (apart from "merge sort" not being legal name and 't1' being declared twice)?
Last edited on
I want to complete the implementation by creating the "merge" but I don't know how!
I want a program to merge (t1, t2, t)
Last edited on
Look at std::merge.
thank you my friend
I'll see,
but I like to see the program or the algorithm of merge function because I want to know how it works :)
Look at std::merge implementation. Either on http://en.cppreference.com/w/cpp/algorithm/merge
or your compiler standard library implementation.
If you would really read the reference documentation for std::merge that is on this site, you would see the phrase
The behavior of this function template is equivalent to:

that is followed by code.
that's nice
Thank you my friends
Topic archived. No new replies allowed.