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

时间:2015-03-28 06:31:31

标签: 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

要做到这一点有没有办法做到这一点,而不是逐个循环所有条目并更新位置?

1 个答案:

答案 0 :(得分:0)

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

相关问题