c# - Listing all permutations and combinations of a string -


how go getting combination , variation of array of strings? let's a, b, c, d expected this, able compute out ab , ba view differents combination.

a ab ac abc abcd acbd ...  b ba bc bcd badc ... 

edit:

currently try code below using list, thinking should make permutation(like set= abcd,bcda,cdab.....) string set in order full list?

    string set = "abcd";      // init list     list<string> subsets = new list<string>();      // loop on individual elements     (int = 1; < set.length; i++)     {         subsets.add(set[i - 1].tostring());          list<string> newsubsets = new list<string>();          // loop on existing subsets         (int j = 0; j < subsets.count; j++)         {             string newsubset = subsets[j] + set[i];             newsubsets.add(newsubset);         }          subsets.addrange(newsubsets);     }      // add in last element     subsets.add(set[set.length - 1].tostring());     subsets.sort(); 

as found difficult understand question apologize limited response. give shot. attempted make program in c display combinations of array of characters similar string, without '\0'. attempt convert code c#.

/* string combos enumerated */ char[] set = { 'a', 'b', 'c', 'd' }; /* length of array */ int setlength = set.length, a, b, c;  /* print combos have 1 value. e.g. a, b, c, d */ (a = 0; < setlength; a++)  {     console.writeline(set[a] + environment.newline); }  /* give 1st value of combo */ (a = 0; < setlength; a++) {     /* give 2nd value. resulting in combos length of 2 */     (b = 0; b < setlength; b++)              {         console.writeline(set[a] + set[b] + environment.newline);     } }  /* 1st value */ (a = 0; < setlength; a++) {     /* 2nd value */     (b = 0; b < setlength; b++)     {         /* 3rd value */         (c = 0; c < setlength; c++)         {             console.writeline(set[a] + set[b] + set[c] + environment.newline);         }     } } /* continue longer combos add more , more loops */ 

output: output different changed fit in single screenshot

output different changed fit in single screenshot hope helped.

edit: found similar question had been answered: listing permutations of different combination of characters please on covers similar topics in question.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -