Question

I would like to zip two arrays in C++ (as in Python) using a standard library function, so is there any equivalent for Python's built-in function zip()?

Était-ce utile?

La solution

int **zip(int *arr1, int *arr2, int length)
{
    int **ret = new int*[length];
    for(int i = 0; i<length; i++)
    {
        ret[i] = new int[2];
        ret[i][0] = arr1[i];
        ret[i][1] = arr2[i];
    }
    return ret;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top