In Java
public int compareTo2(String that) {
String sig1 = this.sort();
String sig2 = that.sort();
return sig1.compareTo(sig2);
}
In C++
int compareTo2 (string that) {
string sig1 = this.sort();
string sig2 = that.sort();
return strcmp(sig1,sig2);
}
The first is a Java program. I translated it to C++ program. Did I write it correctly? Thank you.
Assuming that with
stringyou talk ofstd::string:std::stringdoesn’t provide a member namedsort. You shall do that withstd::sort:And
strcmpis thought to be used withconst char*s, so you have to write:Finally,
thishas to be dereferenced: