Recursion/iteration troubles, transforming an array of words into phrases -
I'm trying to create a list of "phrases" using an array of word lists. I have an array that looks like this:
[['big', 'small', 'wild'], ['brown', 'black', 'spotted'], ['' Cat '', 'dog']]
As a result, the first word is the first word in "phrase"; second is the second word, and so on. The number of word lists is variable, it can have two lists or five lists of words. I am having trouble making that array look like this:
[['Big', 'brown', 'cat'], ['big', 'brown As a result, the order of the array does not matter, but if the original array has three, then ... as a result of the word lists, the resulting nested array should be three words long. I am writing it in javascript, but in the language you prefer, the Rican concept must be basically the same.
How about an implementation in C #? Unfortunately, the manipulation algorithm in the list hides a little.
By using the system. Colllections.Generic; Namespace CSSRPTist {class program {static list & lt; List & lt; String & gt; & Gt; BuildResult (list & lt; list & lt; string & gt; crosspages, list & lt; list & lt; string & gt; & gt; word) {// recurs every step // removes the first list of words And creates a new list of all those phrases that include all the // include a combination of the previous phrase and one word // Remove the words to be added to the list & lt; String & gt; Words: Aad = words [0]; Words.RemoveAt (0); // Create new list of phrases list & lt; List & lt; String & gt; & Gt; NewPhrases = New list & lt; List & lt; String & gt; & Gt; (); Exotic Words (Add String word to word) {foreach (list & lt; string & gt; see in curprash) {// Create new phrase list & lt; String & gt; NewPhrase = New list & lt; String & gt; (); NewPhrase.AddRange (curPhrase); NewPhrase.Add (word); // Add to the list. NewPhrases.Add (newPhrase); }} If (word count & gt; 0) {// recurs Return BuilderSult (new phrase, word); } // There is no other word, so we did a new return; } Fixed zero main (string [] args) {list & lt; List & lt; String & gt; & Gt; Word = new list & lt; List & lt; String & gt; & Gt; {New list & lt; String & gt; {"Big", "small", "wild"}, new list & lt; String & gt; {"Brown", "black", "spot"), new list & lt; String & gt; {"Cat dog"}}; WriteWords (word); // Start a recursion list with an empty list & lt; List & lt; String & gt; & Gt; Empty list = new list & lt; List & lt; String & gt; & Gt; {New list & lt; String & gt; ()}; & Lt; From the list & lt; String & gt; & Gt; Result = BuilderSteelt (word of mouth, word); WriteWords (results); } Fixed zero empty word (list & lt; list & lt; string & gt; & gt; word) {foreach (list & lt; string & gt; word list in terms) {foreach (string word in wordList) {System. Console.Write (word + ""); } System.Console.WriteLine (""); }}}
}
Comments
Post a Comment