C # permutation and combination algorithms

Source: Internet
Author: User
// Sort and combine public class fullarrange {// <summary> /// sort and combine /// </Summary> /// <Param name = "str"> string </ param> // <Param name = "splitstr"> delimiter, for example, ";" </param> // <returns> </returns> Public static list <string> getarrangeresult (string STR, string splitstr) {STR = Str. trim (); If (string. isnullorempty (STR) {return new list <string> ();} else if (Str. length = 1) {return new list <string> {STR };} else if (Str. length = 2) {string [] CA = Str. split (New char [] {convert. tochar (splitstr)}); return new list <string> () {Ca [0]. tostring () + splitstr + Ca [1]. tostring (), Ca [1]. tostring () + splitstr + Ca [0]. tostring () };} else {string [] array = Str. split (New char [] {convert. tochar (splitstr)}); List <string> splittemp = new list <string> (); List <string> temp = getarrangestring (array [0]. tostring (), array [1]. tostring (); For (INT I = 2; I <array. length; I ++) {int COUNT = temp. count; For (Int J = 0; j <count; j ++) {temp. addrange (getarrangestring (temp [J], array [I]); temp. remove (temp [J]); j --; count -- ;}} foreach (VAR item in temp) {var mstr = ""; foreach (VAR s in item) {mstr + = S. tostring () + ";";} splittemp. add (mstr. trimend (';');} return splittemp;} public static list <string> getarrangestring (string parent, string child) {list <string> temp = new list <string> (); For (INT I = 0; I <= parent. length; I ++) {temp. add (parent. insert (I, child. tostring ();} return temp ;}}
Related Article

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.