public static int select(List<Integer> list, int index) {

        int medianOfMedians = medianOfMedians(list);
        int q = medianOfMedians;
        List<Integer> partitionList = new ArrayList(list);
        int beforeRank = 0;

        int i = 0;
        int j = partitionList.size() - 1;
        do {            
            while (partitionList.get(i) < q) ++i;
            while (partitionList.get(j) > q) --j;
            if (i <= j) {
                int temp = partitionList.get(i);
                partitionList.set(i, partitionList.get(j));
                partitionList.set(j, temp);
                if (partitionList.get(i).equals(partitionList.get(j))) {
                    j--;
                }
            }
        } while (i < j);
        
        beforeRank = partitionList.indexOf(q);
        
        if (beforeRank > index) {
            return select(partitionList.subList(0, beforeRank), index);
        } else if (beforeRank < index) {
            return select(partitionList.subList(beforeRank + 1, partitionList.size()), index - beforeRank - 1);
        } else {
            return q;
        }
    }