順列 C#
usingSystem;usingSystem.Collections.Generic;namespacePermutation{classProgram{staticvoidMain(string[]args){newProgram();}publicProgram(){List<int>data=newList<int>{1,2,3,4};List<List<int>>perm=GetPermutation(data);foreach(List<int>pinperm){Console.WriteLine(string.Join(",",p));}}privateList<List<int>>GetPermutation(List<int>data){List<List<int>>perm=newList<List<int>>();if(data.Count==0){perm.Add(data);returnperm;}for(inti=0;i<data.Count;i++){inthead=data[i];List<int>dataCopy=newList<int>(data);dataCopy.RemoveAt(i);List<List<int>>childPerm=GetPermutation(dataCopy);foreach(List<int>childinchildPerm){child.Insert(0,head);perm.Add(child);}}returnperm;}}}