public ArrayList<ArrayList<Integer>> permute(int[] num) {
        LinkedList<TailStack<Integer>> mappers = search(num.length);
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        for (TailStack<Integer> mapper : mappers){
            ArrayList<Integer> tmp = new ArrayList<Integer>();
            for(Integer i : mapper){
                tmp.add(num[i]);
            }
            result.add(tmp);
        }
        
        return result;
    }