我要用 comparator 功能來做整數的比對
但是發現它似乎只能處理字串,但是整數比對沒考慮位數
舉例: 18 13 11 10 10
加入 100 來排序此時會變成
18 13 11 100 10 10
100後面的0沒有被考慮進去
有沒有解決方法呢?
private Key[] pq; // store items at indices 1 to n
private int n; // number of items on priority queue
private Comparator<Key> comparator; // optional comparator
private boolean less(int i, int j) {
if (comparator == null) {
return ((Comparable<Key>) pq[i]).compareTo(pq[j]) < 0;
}
else {
return comparator.compare(pq[i], pq[j]) < 0;
}
}