Internet & Technology

Program to find all possible arrangements of a string

How to find all possible arrangements of a string using a computer program... A nice and clean way to do it is using a counter.
of 2
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
  C# Program to find all possiblearrangements of a given string Quasar S. Chunawalla This program accepts a string from the user and finds all possible arrangement of the letters thatmake up the string. For example, if you enterTAPThe possible arrangements are 6 :TAPTPAAPTATPPATPTAThe program is given in the listing below – class Program{static voidMain(string[] args) {Console.WriteLine( Enter a string : ); stringstr =Console.ReadLine(); char[] A = str.ToCharArray();intl = A.Length;int[] indexes =new int[l]; intcount = 0;intflag;/*The value of count is l to the power l*/intm = 1;intmaxCount = 1;while(m <= l){maxCount = maxCount * l;m = m + 1;}while(count<maxCount){count++;flag = 0;//Increment the indexes counterindexes[l - 1] = indexes[l - 1] + 1;//Make sure that if the digits over the subsequent higherdigit is updatedfor(intj = 1; j <= l - 1; j++) {if(indexes[l - j] == l)  {indexes[l - j - 1]++;indexes[l - j] = 0;}}/*Check if any pair from all possible pairs contain thesame digits*/for(intx = 0; x < l - 1; x++) {for(inty = x + 1; y < l; y++) {if(indexes[x] == indexes[y]){flag = 1;break;}}}if(flag == 0){Console.WriteLine();/*Display the indexes array*/for(intk = 0; k < l; k++) {Console.Write(A[indexes[k]] + ); }}}}}
Similar documents
View more...
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks