Created
March 7, 2011 02:12
-
-
Save ts-3156/857971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ArrayList<String> sortDescending(HashMap<String, Integer> map){ | |
ArrayList<String> dataToReturn = new ArrayList<String>(); | |
Set<String> keySet = map.keySet(); | |
for(int i = 0; i < keySet.size(); i++){ | |
int maxCount = -1; | |
String maxName = ""; | |
for(String name: keySet){ | |
boolean alreadyAdded = false; | |
for(String addedName: dataToReturn){ | |
if(addedName.equals(name)){ | |
alreadyAdded = true; | |
break; | |
} | |
} | |
if(alreadyAdded) | |
continue; | |
int curCount = map.get(name); | |
if(curCount > maxCount){ | |
maxCount = curCount; | |
maxName = name; | |
} | |
} | |
if(maxCount != -1){ | |
dataToReturn.add(maxName); | |
} | |
else | |
break; | |
} | |
return dataToReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment