Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ø
øving 9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Awesome group
øving 9
Commits
194f4e5b
Commit
194f4e5b
authored
2 years ago
by
Pedro Pablo Cardona Arroyave
Browse files
Options
Downloads
Patches
Plain Diff
Small change
parent
5fa19d91
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Task9.java
+25
-0
25 additions, 0 deletions
src/Task9.java
with
25 additions
and
0 deletions
src/Task9.java
+
25
−
0
View file @
194f4e5b
...
@@ -185,6 +185,31 @@ class Graph{
...
@@ -185,6 +185,31 @@ class Graph{
}
}
return
-
1
;
return
-
1
;
}
}
public
List
<
Edge
>
getShortestPath
(
int
startNumber
,
int
destinationNumber
){
PriorityQueue
<
Edge
>
priorityQueue
=
new
PriorityQueue
<>();
int
nodeSize
=
nodes
.
size
();
int
[]
pathWeight
=
new
int
[
nodes
.
size
()];
Arrays
.
fill
(
pathWeight
,
Integer
.
MAX_VALUE
);
List
<
Edge
>[]
pathToNodes
=
new
List
[
nodeSize
];
pathWeight
[
startNumber
]
=
0
;
Arrays
.
fill
(
pathToNodes
,
new
ArrayList
<>());
priorityQueue
.
addAll
(
adjacencyList
.
get
(
startNumber
));
while
(!
priorityQueue
.
isEmpty
()){
Edge
nextEdge
=
priorityQueue
.
poll
();
int
nextNode
=
nextEdge
.
destination
();
int
start
=
nextEdge
.
start
();
int
currentSum
=
pathWeight
[
start
]
+
nextEdge
.
drivingTime
();
if
(
currentSum
<
pathWeight
[
nextNode
]){
pathWeight
[
nextNode
]
=
currentSum
;
pathToNodes
[
nextNode
]
=
new
ArrayList
<>(
pathToNodes
[
start
]);
pathToNodes
[
nextNode
].
add
(
nextEdge
);
priorityQueue
.
addAll
(
adjacencyList
.
get
(
nextNode
));
}
}
return
pathToNodes
[
destinationNumber
];
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment