赞
踩
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.util.PriorityQueue;
public class Process implements Comparable {
private String name;
private int priority;
public Process(String name, int priority) {
this.name = name;
this.priority = priority;
}
public String toString() {
return "(" + this.name + "," + this.priority + ")";
}
public int compareTo(Process p) {
// TODO Auto-generated method stub
return this.priority - p.priority;
}
}
class Process_ex {
public static void main(String args[]) {
Process process[] = {new Process("A", 4), new Process("B", 3), new Process("C", 5),
new Process("D", 4), new Process("E", 10), new Process("F", 1)
};
PriorityQueue que = new PriorityQueue();
System.out.print("入队进程:");
for (int i = 0; i < process.length; i++) {
que.add(process[i]);
System.out.print(process[i] + "");
}
System.out.print("\n出队进程");
Process p = null;
while (!que.isEmpty())
System.out.print(que.poll());
System.out.println();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。