views:

84

answers:

2

I would like to generate permutations of string words that are inputted from a file. I know the count and was wondering if there is an easy way to do this using an arraylist.

A: 

Since this doesn't have a homework tag, I'd suggest using a std::vector of words and std::next_permutation. (If it had a homework tag, I'd suggest how to implement something like std::next_permutation.)

sbi
Sometimes all these libraries take the fun out of programming ;)
WhirlWind
Its not homework...I have a bunch of nouns I compiled by using SharpNLP and now wish to produce permutations of length 5 using each noun. I realize its a recursive method required but not sure how to implement it since all searches on this does not produce a clear method. But I will keep checking thanks..
vbNewbie
+1  A: 

Great article on MSDN Magazine: String Permutations

Combination Generator in Linq (this one has a LINQ based answer)

Using the code provided in the above link:

string str = "leniel";

var permutations = GetPermutations(str);

foreach (string s in permutations)
{
    Console.WriteLine(s);
}

Console.WriteLine(permutations.Count()); // 720 permutations

Console.ReadLine();

More links to help:

Listing all permutations of a string/integer

Permutations with LINQ

Generating (word) combinations (permutations) out of a string

Is there a .NET library that can do string permutations or string expansion?

Are there any better methods to do permutation of string?

Generate list of all possible permutations of a string

Leniel Macaferi
Thanks for the help. I just realized I had it wrong and what I need to do is combinations of the strings with the order not changing but selection does. Also it should be n(n-1)/2 results.
vbNewbie