Этот код en C # предназначен для получения всех комбинаций элементов в зубчатом массиве:
static void Main(string[] args)
{
bool exit = false;
int[] indices = new int[3] { 0, 0, 0 };
string[][] vectores = new string[3][];
vectores[0] = new string[] { "A", "B", "C" };
vectores[1] = new string[] { "A", "B" };
vectores[2] = new string[] { "B", "D", "E", "F" };
string[] item;
int[] tamaños = new int[3]{vectores[0].GetUpperBound(0),
vectores[1].GetUpperBound(0),
vectores[2].GetUpperBound(0)};
while (!exit)
{
item = new string[]{ vectores[0][indices[0]],
vectores[1][indices[1]],
vectores[2][indices[2]]};
Console.WriteLine("[{0},{1},{2}]={3}{4}{5}", indices[0], indices[1], indices[2], item[0], item[1], item[2]);
GetVector(tamaños, ref indices, ref exit);
}
Console.ReadKey();
}
public static void GetVector(int[] tamaños, ref int[] indices, ref bool exit)
{
for (int i = tamaños.GetUpperBound(0); i >= 0; i--)
{
if (tamaños[i] > indices[i])
{
indices[i]++;
break;
}
else
{
//ULTIMO ITEM EN EL ARRAY, VALIDAR LAS OTRAS DIMENSIONES SI YA ESTA EN EL ULTIMO ITEM
if (!ValidateIndexes(tamaños, indices))
indices[i] = 0;
else
{
exit = true;
break;
}
}
}
}
public static bool ValidateIndexes(int[] tamaños, int[] indices)
{
for (int i = 0; i < tamaños.Length; i++)
{
if (tamaños[i] != indices[i])
return false;
}
return true;
}
Выход выглядит как
[0,0,0] = ААВ
[0,0,1] = ААР
[0,0,2] = СНП
[0,0,3] = ААР
[0,1,0] = АББ
[0,1,1] = ABD
[0,1,2] = АВА
[0,1,3] = ABF
[1,0,0] = BAB
[1,0,1] = BAD
[1,0,2] = БАЭ
[1,0,3] = БАФ
[1,1,0] = В
[1,1,1] = BBD
[1,1,2] = BBE
[1,1,3] = BBF
[2,0,0] = САВ
[2,0,1] = CAD
[2,0,2] = САЙ
[2,0,3] = CAF
[2,1,0] = С
[2,1,1] = CBD
[2,1,2] = CBE
[2,1,3] = БФК