gpt4 book ai didi

java - 错误: Type Queue Does Not Take Parameter - What's the difference between Queues and Priority Queues?

转载 作者:行者123 更新时间:2023-12-01 13:29:33 25 4
gpt4 key购买 nike

我收到错误消息“类型队列不接受参数”。当我将更改队列行替换为 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);
}
}

最佳答案

如果您想使用队列而不是 PriorityQueue,请创建具有 Queue 接口(interface)的 LinkedList 类的对象。

import java.util.*;
.....
Queue<Integer> q = new LinkedList<Integer>();
.....

如果此后仍不起作用,请尝试使用指定的导入语句:

import java.util.LinkedList;
import java.util.Queue;

有时会出现不接受java.util.*参数的情况

code snippet of error due to java.util.*

关于java - 错误: Type Queue Does Not Take Parameter - What's the difference between Queues and Priority Queues?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21645825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com