There are a number of ways to do this, and here's an algorithm that's easiest to understand, but it's a little bit harder.
Import java.util.ArrayList;
Import Java.util.Arrays;
Import java.util.List;
public class Fullsort {//num set to the length of the array to be arranged is the choice to arrange private static int NUM = 3; /** * Recursive algorithm: divides the data into two parts, recursively moves the data from the left to the right to implement the choice arrangement * * @param datas * @param target/private static V
OID sort (list datas, list target) {if (target.size () = NUM) {for (Object obj:target)
System.out.print (obj);
System.out.println ();
Return
for (int i = 0; i < datas.size (); i++) {List Newdatas = new ArrayList (datas);
List newtarget = new ArrayList (target);
Newtarget.add (Newdatas.get (i));
Newdatas.remove (i);
Sort (Newdatas, newtarget); } public static void Main (string[] args) {string[] datas = new string[] {"A", "B", "C", "
D "}; Sort (arrays.aslist(datas), New ArrayList ()); }
}
This code inside the return use is very powerful, everybody oneself slowly realize ~
Here is a full array of algorithms, but also very clever simple ~
public class allsort{public
static void Main (string[] args) {
char buf[]={' A ', ' B ', ' C '};
Perm (buf,0,buf.length-1);
}
public static void Perm (char[] buf,int Start,int end) {
if (start==end) {//when only one letter in an array is required to be fully arranged, it can be output as long as it is specified (special case) for
(int i=0;i<=end;i++) {
System.out.print (BUF);
}
System.out.println ();
}
else{//multiple alphabetic (Universal)
for (int i=start;i<=end;i++) {//(let pointer start point to each number)
char temp=buf[start];// Exchange array the first element buf[start]=buf with the subsequent elements
;
Buf=temp;
Perm (buf,start+1,end);//Subsequent elements recursive full arrangement
temp=buf[start];//restore the swapped array to
buf[start]=buf;
Buf=temp}}}}