Foreach 对 HashMap 无效?和一般优先级队列问题
public static void Dijk(HashMap<String, HashMap<String, Integer>> map, String go, String stop){
PriorityQueue pq = new PriorityQueue();
for (String x: map){
}
}
为什么编译器告诉我不能在这里使用 foreach 循环?
另外,这是大型程序的较小部分,但我对优先级队列没有太多经验,我想用它来保存
我这样做对吗? (我本质上使用 PQ 作为二进制堆)(此方法将实现 Dijkstra 算法)
提前感谢您的帮助/回答!
public static void Dijk(HashMap<String, HashMap<String, Integer>> map, String go, String stop){
PriorityQueue pq = new PriorityQueue();
for (String x: map){
}
}
Why is the complier telling me I can't use a foreach loop here?
Also this is smaller section of a large program but I haven't had much experience with priority queues I want to use it to hold a <String, int> //or Integer
am I doing this right? (Im using the PQ as a binary heap essentially) (this method will be implementing Dijkstra's algorithm)
Thank you for your help/answers in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设你打算迭代HashMap的键,你应该尝试
至于优先级队列,看看Java集合PriorityQueue
Assuming you intend to iterate over the keys of the HashMap, you should try
As for the priority queue, take a look at the Java collection PriorityQueue