`
personbeta
  • 浏览: 159967 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

n个数的全排列

    博客分类:
  • java
 
阅读更多
public class Test{
	public void swap(int[] list,int i,int j){
		int temp=list[i];
		list[i]=list[j];
		list[j]=temp;
	}
	public void perm(int[]list,int offset,int count){
		
		if(offset==count){
			for(int i=0;i<count;i++)
				System.out.print(list[i]+" ");
			System.out.println();
			
		}else{
			for(int i=offset;i<count;i++){
				swap(list,i,offset);
				perm(list,offset+1,count);
				swap(list,offset,i);
			}
		}
	}
	public static void main(String[]args){
		Test test=new Test();		
		int list[] = {1, 2, 3, 4};
		test.perm(list,0,4);
		

	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics