void MergeArrays(int *array1, int len1, int *array2, int len2, int *array)
{
int index1 = 0;
int index2 = 0;
int index = 0;
while(index1 < len1 && index2 < len2)
{
if (array1[index1++] <= array2[index2++])
{
array[index++] = array1[index1];
}
else
{
array[index++] = array2[index2];
}
}
if (index1 < len1-1)
{
for (index1 = len2; index1 < len1; index1++)
{
array[index++] = array1[index1];
}
}
else
{
for (index2 = len1; index2 < len2; index2++)
{
array[index++] = array2[index2];
}
}
}