递归求解全排列
import java.util.Arrays; public class Main { public static void main(String[] args) { char [] data = {'A','B','C'}; f(data,0); } private static void f(char [] data,int k){ if(k == data.length){ System.out.println(Arrays.toString(data)); } for (int i = k; i < data.length; i++) { char temp = data[k]; data[k]=data[i]; data[i]=temp; f(data,k+1); temp=data[k]; data[k]=data[i]; data[i]=temp; } } }
posted on 2018-03-31 20:06 ZhangのBlog 阅读(106) 评论(0) 编辑 收藏 举报