What is the point of adding and removing the element from Priority Queue in the given dijkstra code?

前端 未结 2 2000
再見小時候
再見小時候 2021-01-29 03:30

I was studying Dijkstra algorithm code given at this link -> https://java2blog.com/dijkstra-java/

Can someone explain the following 2 parts of the code?

1) Why a

2条回答
  •  无人共我
    2021-01-29 04:17

    1) PriorityQueue only evaluates priority when entries are inserted. Just changing the priority on v will not cause this evaluation, so it will have no effect.

    2) The basic contract for compareTo is that it returns 0 iff both instances or considered equal. 1 if this is considered "bigger" -1 if this is considered "smaller". Double.compare(..) creates this semantic for a Double value.

提交回复
热议问题