I'm trying to implement a mergesort tree in C++, but I'm getting the error
note: template argument deduction/substitution failed:
C:\Users\IT Services\Documents\mergetree.cpp:15:38: note: candidate expects 6 arguments, 2 provided
tree[k]=merge(tree[2*k],tree[2*k+1]);
Here's the code:
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> tree;
int n;
void update (int k, vector<int> vect)
{
k+=n;
tree[k]=vect;
for (k/=2;k>=1;k/=2)
{
tree[k]=merge(tree[2*k],tree[2*k+1]);
}
}
vector<int> merge (vector<int> arr1, vector<int> arr2)
{
int a1=arr1.size(), a2=arr2.size();
vector<int> sortvect(a1+a2);
int i=0,j=0,k=0;
while (i<a1&&i<a2) sortvect[k++]=((arr1[i]<arr2[j])?arr1[i++]:arr2[j++]);
while (i<a1) sortvect[k++]=arr1[i++];
while (j<a2) sortvect[k++]=arr2[j++];
return sortvect;
}
int main()
{
cin>>n; tree.resize(2*n,{0});
int a;
for (int i=0;i<n;i++)
{
cin>>a;
update(i,{a});
}
}
Clearly, the merge function does not require 6 arguments. Why does the compiler think it does?
[Also, please ignore the terrible way the code is written. I'm practicing for an upcoming contest, and clean coding conventions are not a priority at the moment.]