Created
January 28, 2018 04:10
-
-
Save keehyun2/50b9b0f04d31d000ac99150b22a66414 to your computer and use it in GitHub Desktop.
CustomString
This file contains hidden or 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
class CustomString implements Comparable<CustomString> { | |
public String str; | |
public CustomString(String str) { | |
this.str = str; | |
} | |
public int compareTo(CustomString cs) { | |
int leng1 = this.str.length(); | |
int leng2 = cs.str.length(); | |
if (leng1 < leng2) return -1; | |
if (leng1 > leng2) return 1; | |
return this.str.compareTo(cs.str); // 길이가 같은 경우만 compareTo 사용함 | |
} | |
} | |
public static void main(String[] args) throws NumberFormatException, IOException { | |
PriorityQueue<CustomString> pq = new PriorityQueue<CustomString>(); | |
pq.add(new CustomString("axcdcc")); | |
pq.add(new CustomString("33")); | |
pq.add(new CustomString("zsdc")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment