This function is intended to take a vector with x,y value pairs of the form {x1, x2, x3, y1, y2, y3} and return a vector with the values shuffled as such {x1, y1, x2, y2, x3, y3}. The size of the vector is 2*n, where n is the number of x values/y values respectively. By using print statements inside the function, I've already determined that the algorithm works.
vector<int> shuffle(vector<int>& nums, int n) {
vector<int> temp;
temp.reserve(2*n);
int xCounter = 0;
int yCounter = n;
for (int i=0; i<2*n; i+=2){
// populate arr x val
temp[i] = (nums[xCounter]);
// populate arr y val
temp[i+1] = (nums[yCounter]);
++xCounter;
++yCounter;
}
return temp;
}
int main()
{
vector<int> yoMomma = {1,2,3,1,2,3};
vector<int> ans;
ans = shuffle(yoMomma,yoMomma.size()/2);
return 0;
}