How to permute a list of objects in C#?
I have a list of objects. I need all possible permutations of those objects.
In C++, there's std::next_permutation()
. I have been trying to find something in the .NET Framework, but came up dry.
What am I missing?
I don't think it's built in to the framework but there's a good article on CodeProject with some samples
http://www.codeproject.com/KB/recipes/Combinatorics.aspx
I also think that there is no permutations() function included in the .NET Framework. But you could always go and implement it yourself...
...in that case you might find this post useful:
Fast permutation -> number -> permutation mapping algorithms
精彩评论