java - 如何更新优先级队列中的位置

标签 java c++ c algorithm location

这是我的场景,我想要一些聪明的解决方案来解决这个问题。

我有 1024 个位置,每个位置都与一个条目相关联。现在我在已有的 1024 个位置之上添加了 1024 个位置。现在我必须更新与旧 1024 位置关联的现有条目的位置。有没有什么聪明的方法可以做到这一点,而无需迭代所有 1024 个条目。

这是场景。

location 0 associated to ==> entry 0
location 1 associated to ==> entry 1
location 2 associated to ==> entry 2
location 3 associated to ==> entry 3
.
.
.
.
location 1023 associated to ==> entry 1023



now i have added new 1024 locations on top. so i have to update the locations of entries as follow

location 0 new location
location 1 new location
location 2 new location
location 3 new location
location 4 new location
.
.
.
.
location 1024 associated to ==> entry 0
location 1025 associated to ==> entry 1
location 1026 associated to ==> entry 2
location 1027 associated to ==> entry 3
location 1028 associated to ==> entry 4
.
.
.
location 2047 associated to ==> entry 1023

要做到这一点,有什么方法可以做到这一点,而无需逐一循环所有条目并更新位置?

最佳答案

PriorityQueue 元素如何与条目元素保持关联? 我认为,您在这里使用了错误的数据结构。

关于java - 如何更新优先级队列中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29314406/

相关文章:

java - EntityManager.persist() 不保存到数据库

java - 了解计算幂集时的递归流程

c++ - QOpenGLFunctions_4_3_与 QOpenGLContext::versionFunctions 的兼容性

C++ - 连续内存和多态性

c - 如何测试字符串是否在c中初始化?

c - 替代 malloc

java - 无法在 habase 谷歌云中将存储的 python 整数返回到 java 中

Java "while"- 循环内的变量

c++ - clang & gcc 以不同的方式解释 cast 系列

c - 从函数返回一个字符串到 main