【发布时间】:2014-03-05 22:21:55
【问题描述】:
我收到错误消息类型队列不采用参数。当我将更改队列行替换为 PriorityQueue 时,此错误消失并且编译正常。有什么区别,如何将其更改为编译和常规队列?
import java.util.*;
public class StackOneTwoMultiply {
public static void main(String[] args) {
int first, second;
Stack<Integer> s = new Stack<Integer>(); //stack called s
PriorityQueue<Integer> q = new PriorityQueue<Integer>();
for (int i = 10; i > 0; i--) { //filling the stack (what order to fill was not specifified)
s.push(i);
}
while (!s.isEmpty()) {
first = s.pop();
second = s.pop();
q.offer(first * second);
System.out.println(q.peek());
}
System.out.print(q);
}
}
【问题讨论】:
-
抱歉你的意思是
Queue<Integer> q = new Queue<Integer>();? -
是的,很抱歉含糊不清。
-
但是您可以创建队列,因为它是
abstract类。你可以在这里创建它:Queue<Integer> q = new PriorityQueue<Integer>(); -
你可以创建
Stack,因为它不是abstract。
标签: java collections parameters queue stack