MCPcopy
hub / github.com/careercup/ctci / sort

Method sort

java/Chapter 11/Question11_2/QuestionB.java:16–38  ·  view source on GitHub ↗
(String[] array)

Source from the content-addressed store, hash-verified

14 }
15
16 public static void sort(String[] array) {
17 Hashtable<String, LinkedList<String>> hash = new Hashtable<String, LinkedList<String>>();
18
19 /* Group words by anagram */
20 for (String s : array) {
21 String key = sortChars(s);
22 if (!hash.containsKey(key)) {
23 hash.put(key, new LinkedList<String>());
24 }
25 LinkedList<String> anagrams = hash.get(key);
26 anagrams.push(s);
27 }
28
29 /* Convert hash table to array */
30 int index = 0;
31 for (String key : hash.keySet()) {
32 LinkedList<String> list = hash.get(key);
33 for (String t : list) {
34 array[index] = t;
35 index++;
36 }
37 }
38 }
39
40 public static void main(String[] args) {
41 String[] array = {"apple", "banana", "carrot", "ele", "duck", "papel", "tarroc", "cudk", "eel", "lee"};

Callers 5

mainMethod · 0.95
sortCharsMethod · 0.45
mainMethod · 0.45
sortCharsMethod · 0.45
getIncreasingSequenceMethod · 0.45

Calls 4

sortCharsMethod · 0.95
putMethod · 0.80
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected