I'm trying to make a custom comparator that will sort an array of integers in the order that a C-LOOK disk algorithm would perform.
I've implemented the Disk Queue as a PriorityQueue and the customer Comparator will be assigned to the Disk Queue list.
I am keeping track of the head position, and utilizing it in the compare method, but it's not quite right.
The first 5 operations added to the queue are [32, 188, 36, 61, 97]. The head position starts at 50. But the first 5 operations after being sorted come out to be [32, 36, 188, 97, 61].
What else should I be doing?
private Comparator<Integer> CLOOK() {
return new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
if (o1 < o2) {
if (o1 > currentHeadPosition) {
return 1;
}
return -1;
}
else if (o1 > o2) {
if (o2 > currentHeadPosition) {
return -1;
}
return 1;
}
else {
return 0;
}
}
};
}
// End CLOOK Comparator
Aucun commentaire:
Enregistrer un commentaire