I am trying to implement merge sort using vector in c++, i am getting following error - 
terminate called after throwing an instance of 'std::bad\_alloc'.
There were other solutions for bad\_alloc but it didn't help. 

problem is merging function-

```
#include<iostream>
#include<vector>
using namespace std;

void print(vector<int> v)
{
    for(int i=0; i<v.size(); i++)
        cout << v[i] << " ";
    cout << endl;
}

vector<int> merging(vector<int> left, vector<int> right)
{
    vector<int> result;
    while((int)left.size()>0 && (int)right.size()>0)
    {
        if((int)left.front()<=(int)right.front()){
            result.push_back(left.front());
            //left.erase(left.begin());
        }
        else{
            result.push_back(right.front());
            //left.erase(right.begin());
        }
    }
        while((int)left.size()>0){
            for(int j=0; j<(int)left.size(); j++)
                result.push_back(left[j]);
        }
        while((int)right.size()>0){
            for(int k=0; k<(int)right.size(); k++)
                result.push_back(right[k]);
        }
    cout << "check merging";
    return result;
}

int main()
{
    vector<int> a, b, result;
    a.push_back(38);
    a.push_back(27);
    b.push_back(43);
    b.push_back(3);
    cout << a.front() << endl;
    print(a);
    cout << endl;
    print(b);
    cout << endl;
    result = merging(a, b);
    print(result);
}

```

thank you