Skip to content

Commit e99b06c

Browse files
committed
Fix
1 parent 594c9d1 commit e99b06c

File tree

2 files changed

+3
-11
lines changed
  • src
    • main/java/com/thealgorithms/datastructures/graphs
    • test/java/com/thealgorithms/datastructures/graphs

2 files changed

+3
-11
lines changed

src/main/java/com/thealgorithms/datastructures/graphs/AStar.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ static void initializeGraph(Graph graph, ArrayList<Integer> data) {
120120
*/
121121
public static PathAndDistance aStar(int from, int to, Graph graph, int[] heuristic) {
122122
// PriorityQueue to explore nodes based on their distance and estimated cost to reach the destination
123-
PriorityQueue<PathAndDistance> queue = new PriorityQueue<>(
124-
Comparator.comparingInt(a -> (a.getDistance() + a.getEstimated()))
125-
);
123+
PriorityQueue<PathAndDistance> queue = new PriorityQueue<>(Comparator.comparingInt(a -> (a.getDistance() + a.getEstimated())));
126124

127125
// Start with the initial node
128126
queue.add(new PathAndDistance(0, new ArrayList<>(List.of(from)), heuristic[from]));

src/test/java/com/thealgorithms/datastructures/graphs/AStarTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import static org.junit.jupiter.api.Assertions.assertNull;
55

66
import java.util.ArrayList;
7+
import java.util.Arrays;
78
import org.junit.jupiter.api.BeforeEach;
89
import org.junit.jupiter.api.Test;
9-
import java.util.Arrays;
1010

1111
public class AStarTest {
1212

@@ -17,13 +17,7 @@ public class AStarTest {
1717
public void setUp() {
1818
// Initialize graph and heuristic values for testing
1919
graph = new AStar.Graph(5);
20-
ArrayList<Integer> graphData = new ArrayList<>(Arrays.asList(
21-
0, 1, 1, null,
22-
0, 2, 2, null,
23-
1, 3, 1, null,
24-
2, 3, 1, null,
25-
3, 4, 1, null
26-
));
20+
ArrayList<Integer> graphData = new ArrayList<>(Arrays.asList(0, 1, 1, null, 0, 2, 2, null, 1, 3, 1, null, 2, 3, 1, null, 3, 4, 1, null));
2721
AStar.initializeGraph(graph, graphData);
2822

2923
heuristic = new int[] {5, 4, 3, 2, 0}; // Heuristic values for each node

0 commit comments

Comments
 (0)