It'd be really to implement in Java, since you could use the Comparator and the built in methods to sort character arrays and compare strings like this:
public class AnagramComparator implements Comparator<String> {
public String sortChars(String s) {
char[] content = s.toCharArray();
Arrays.sort(content);
return new String(content);
}
public int compare(String s1, String s2) {
return sortChars(s1).compareTo(sortChars(s2));
}
}
But I'm wondering how would one go about implementing this in C++? Coding the C++ equivalent of the built-in methods used in the above Java code is definitely one option. Is there any other intelligent way?