public void sortByFrequence(Integer arr[]){
        Map<Integer,SortNode> countMap = new HashMap<Integer,SortNode>();
        int index = 0;
        for(int a : arr){
            if(countMap.containsKey(a)){
                SortNode s = countMap.get(a);
                s.count++;
            }else{
                SortNode s = new SortNode();
                s.count = 1;
                s.firstIndex = index;
                countMap.put(a, s);
            }
            index++;
        }
        
        FrequenceComparator freqComparator = new FrequenceComparator(countMap);
        Arrays.sort(arr,freqComparator);
    }
http://www.geeksforgeeks.org/sort-elements-by-frequency/
src/com/interview/sort/SortArrayByFrequence.java