#include<iostream>
#include<vector>
using namespace std;
vector<int> mix(vector<int> v1, vector<int> v2)
{
vector<int> newVec{v1.at(0), v2.at(0)};
if(v2.size()+2>1){
vector<int> restV1(v1.begin() + 1, v1.end());
vector<int> restV2(v2.begin() + 1, v2.end());
vector<int> call_vec = mix(restV1, restV2);
newVec.reserve(newVec.size());
vector<int> newVeca=newVec;
for(size_t i(0);i<newVeca.size();i++){
cout<< newVeca[i]<< "|";
}
}
return newVec;
}
int main()
{
vector<int> v1{1,2,3,4};
vector<int> v2{5,6,7,8};
mix(v1,v2);
return 0;
}
What I have tried:
Hey every one !!!
I have this homework, that we need to mack it without loop and i have a trouble understanding, the tow thing here
1- why the new-Vec is not in the right order (is that from the recursion or somthing i done wrong in my code )
2- i coudnt get the last tow integer in add the new integer
everytime i'm treing to increse the size in if ( if(v2.size()+2>1))i get this error:
(terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0))
Write a function that gets two vectors of int values as parameters and returns a vector of int values as a return value. The returned vector should always contain alternately a value from the first parameter and a value from the second parameter (starting with the first value from the first parameter). The relative order of the values should be the same in the result vector as in the input vectors. If the two input vectors are of different lengths, the remainder of the longer vector is unchanged
Parameter: Ergebnis:
{1,2,3} {4,5,6} {1,4,2,5,3,6}
{1,2,3,4,5,6} {7,8,9} {1,7,2,8,3,9,4,5,6}