Need help with merge sort 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);
    }
}
I think you need mergesort() to call a second function that does the work:
1
2
// Merge sort the sorted subvectors [i1,i2) and [i2,i3)
mergesort(vector<T>::iterator i1, vector<T>::iterator i2, vector<T>::iterator i3);

Topic archived. No new replies allowed.