Solved

String permutation pseudo Code

Posted on 2011-09-14
5
839 Views
Last Modified: 2012-05-12
Can you please give pseudo code  algorithm for this code

using System;
using System.Text;

namespace Permutations
{
        class Permute
        {
                 private void swap (ref char a,ref char b)
                 {
                        if(a==b)return;
                        a^=b;
                        b^=a;
                        a^=b;
                  }

                  public void Set_Permutation(char[] list)
                  {
                        int arrayLength=list.Length-1;
                        Permutation_Method(list,0,arrayLength);
                  }

                  private void Permutation_Method (char[] list,int k,int m)
                  {
                      // k intial index passed 
                      // m size of char array
                        int i;
                        if(k == m)  // ---------- What is this Condition ?
                           {
                                 Console.Write(list);
                                 Console.WriteLine(" ");
                            }
                        else
                             for(i = k; i <= m; i++) //  why i=k ?
                            {
                                   swap(ref list[k], ref list[i]);  // what does this Swap doing ?

                                    //recursive call
                                   Permutation_Method (list, k+1, m);

                                   swap(ref list[k], ref list[i]);   // what does this Swap doing ?
                            }
                   }
         }

         class Class1
        {
               static void Main()
               {

                      Permute objPermutation =new Permute();
                      string str="abc";
                       char[] mycharArray=str.ToCharArray();
                       /*calling the permute*/
                      objPermutation.Set_Permutation(mycharArray);
                  }
           }

}

Open in new window


0
Comment
Question by:N_Sri
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
tampnic earned 500 total points
ID: 36542340
Is http://www.dreamincode.net/code/snippet4662.htm what you are trying to accomplish?

http://weblogs.sqlteam.com/mladenp/archive/2006/03/19/9350.aspx gives a good explanation of string reversal using recursion.

Cheers,
   Chris
0
 
LVL 7

Assisted Solution

by:tampnic
tampnic earned 500 total points
ID: 36542360
Disregard the code snippet above - I was making a couple of notes - forgot to remove the code from my final post. Some comments in it aren't exactly correct. The links I gave you are good though.

Cheers,
  Chris
0
 

Author Comment

by:N_Sri
ID: 36545166
@tampnic

I am sure you did not understood the code .The code is for  String Permutation.

I am requesting String permutation pseudo code for the which I gave
0
 

Author Closing Comment

by:N_Sri
ID: 36707665
You did not understood the question.  Very poor answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now