Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (selected.size() < g.size() && !pq.isEmpty()) {
- boolean can_continue = false;
- NodeT<String> u = null;
- while (!pq.isEmpty()) {
- u = pq.poll();
- if (!selected.contains(u)) {
- selected.add(u);
- can_continue = true;
- break;
- }
- }
- if (!can_continue) {
- break;
- }
- for (PairT<NodeT<String>, Integer> pair : g.adjList(u)) {
- if (!selected.contains(pair.first())
- && distances[g.indexOf(pair.first())] > distances[g.indexOf(u)] + g.distance(u, pair.first())) {
- distances[g.indexOf(pair.first())] = distances[g.indexOf(u)] + g.distance(u, pair.first());
- pq.offer(pair.first());
- }
- }
- }
Add Comment
Please, Sign In to add comment