Algorithm -- full arrangement (c #)

Source: Internet
Author: User

It may take a day before you come out to work, and you will find that you don't have to learn well in college. Now you have to pick up a lot of things. According to a complete. net self-learning plan, it is now a learning stage of algorithms. I want to share some experiences ~ This time I want to talk about the full arrangement. "For example, a, B, and c are arranged in the following ways: abc, acb, bac, bca, cab, and CBA. N elements are arranged in a total of n! ." The book uses a recursive method. It is a bit strange because it uses the C ++ language ~ A non-recursive method is coming up with a radical expression. It is written in C #. I hope it can be used as a reference. Thank you.



Class Perm
...{
Private List <string> permPreList;
Private List <string> permedList;

Public Perm (List <string> list)
...{
PermPreList = list;
PermedList = new List <string> ();
}

Public List <string> PermedList
...{
Get
...{
Return permedList;
}
}

Public void GetPerm ()
...{
For (int I = 0; I <permPreList. Count; I ++)
...{
String first = permPreList [I];

For (int j = 0; j <permPreList. Count; j ++)
...{
If (j! = I)
...{
String second = permPreList [j];

For (int k = 0; k <permPreList. Count; k ++)
...{
If (k! = J & k! = I)
...{
String third = permPreList [k];

PermedList. Add (first + second + third );
}
}
}
}
}
}
}

Throw more bricks ~.~

 



<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.