i have two numbers 1,2 in one array.Now i want to generate all the possible combinations of arrays(of size=5) like
1,2,0,0,0 ||
2,1,0,0,0 ||
1,0,2,0,0
.
.
.
.
.
I tried to write a recursive function but its not working
Now I want to solve this using LINQ because the code will be considerably small.
Please help me
LINQ is excellent for searching; it’s much worse at generating, so it is a wrong tool for the job. So is recursion (although it is a better choice than LINQ). What you need is two nested loops, like this:
Here is what the code does: at each iteration of the inner loop it places the first and the second element from the
elementsarray at distinct positionsiandj. Nested loops go from0to5, making sure all position combinations are covered.