Here is the code:
(It takes a list of any length and prints all possible computational pairs recursively)
static void Function(List<String> list, int z = -1, int x = -1)
{
if (x == -2 || z == -2) { x = list.Count; z = 0; }
x--;
if (x >= z) Function(list, z, x);
else
{
z++;
x = list.Count - 1;
if (z < list.Count-1) Function(list, z, x);
}
Console.Write("{0}-:-{1}, ", list[z], list[x]);
}
And here would be the output for a list of strings { "A", "B", "C", "D"}:
D-:-D, C-:-D, C-:-C, B-:-D, B-:-C, B-:-B, A-:-D, A-:-C, A-:-B, A-:-A
No comments:
Post a Comment