Java帮助:优先队列
我有一个名为 jobType 的类
package pcs_assignment_2;
public class JobType
{
private int ID;
private double aTime;
private double sTime;
public JobType(int ID, double aTime, double sTime)
{
this.ID = ID;
this.aTime = aTime;
this.sTime = sTime;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public double getaTime() {
return aTime;
}
public void setaTime(double aTime) {
this.aTime = aTime;
}
public double getsTime() {
return sTime;
}
public void setsTime(double sTime) {
this.sTime = sTime;
}
public String toString() {
return "JobType{" + "ID=" + ID + "aTime=" + aTime + "sTime=" + sTime + '}';
}
}
现在我想要的是 JobType 类型的 PriorityQue,它根据 sTime 对队列进行排序。是否可以?
I have a class called jobType
package pcs_assignment_2;
public class JobType
{
private int ID;
private double aTime;
private double sTime;
public JobType(int ID, double aTime, double sTime)
{
this.ID = ID;
this.aTime = aTime;
this.sTime = sTime;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public double getaTime() {
return aTime;
}
public void setaTime(double aTime) {
this.aTime = aTime;
}
public double getsTime() {
return sTime;
}
public void setsTime(double sTime) {
this.sTime = sTime;
}
public String toString() {
return "JobType{" + "ID=" + ID + "aTime=" + aTime + "sTime=" + sTime + '}';
}
}
Now what I wanna have is a PriorityQue of Type JobType which sorts the queue on the basis of sTime. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(4)
沫雨熙2024-12-11 03:37:16
将 PriorityQueue
与 Comparator
结合使用。请参阅 http://download.oracle.com/javase/1,5.0/docs/api/java/util/PriorityQueue.html#PriorityQueue(int,%20java.util.Comparator)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
需要编写一个自定义比较器,请参见下面的代码。
这里队列的初始容量为10。
A custom comparator needs to be written, see the code below.
here 10 in the initial capacity of the queue.