java全排序

 Problem  
  将一个字符组全排序    
   
  Input  
  一个长度小于10的字符串,该字符串由数字1~9组成。字符不会重复出现。    
   
  Output  
  按数字在输入串中出现的次序从小到大的顺序输出该字符组的全排序    
   
  Sample   Input  
  132  
   
  Sample   Output  
3
32
321
31
312
2
23
231
21
213
1
13


132
12
123

程序代码如下:

  1. import java.util.*; 
  2. public class T2 { 
  3.     public static void main(String[] args) throws Exception{ 
  4.         String[] array = new String[]{"3","2","1"}; 
  5.         listAll(Arrays.asList(array),""); 
  6.         
  7.     } 
  8.     
  9.     public static void listAll(List<String> candidate, String prefix){ 
  10.         
  11.         System.out.println(prefix); 
  12.         
  13.         forint i=0; i < candidate.size(); i++ ) { 
  14.             List<String> temp = new ArrayList<String>(candidate); 
  15.             listAll(temp, prefix+temp.remove(i)); 
  16.         } 
  17.     } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值