java 笛卡爾積(迴圈)

bei_fang_du_lang發表於2016-09-20
 @SuppressWarnings({ "rawtypes", "unchecked" })
	public static List Dikaerji(List listSrc){
    	List listOne = (List) listSrc.get(0);
    	List result = new ArrayList();
    	for(int i = 1; i < listSrc.size(); i++){
    		List listTwo = (List)listSrc.get(i);
    		List temp = new ArrayList();
    		for(int j = 0; j < listOne.size(); j++){
    			for(int k = 0; k < listTwo.size(); k++){
    				List cut = new ArrayList();
    				if(listOne.get(j) instanceof List){
    					cut.addAll((List)listOne.get(j));
    				}else{
    					cut.add(listOne.get(j));
    				}
    				if(listTwo.get(k) instanceof List){
    					cut.addAll((List)listTwo.get(k));
    					System.out.println("OK");
    				}else{
    					cut.add(listTwo.get(k));
    				}
    				temp.add(cut);
    			}
    		}
    		listOne = temp;
    		result = temp;
    	}
    	return result;
    }

相關文章