Skip to content

Commit ea5a251

Browse files
author
Jegors Cemisovs
committed
Fixed issue #13
1 parent 2e988b6 commit ea5a251

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package lv.id.jc.algorithm.graph;
22

3+
import java.util.ArrayDeque;
34
import java.util.HashMap;
45
import java.util.HashSet;
56
import java.util.LinkedList;
@@ -11,18 +12,18 @@
1112

1213
/**
1314
* Algorithm for finding the shortest paths between nodes in a graph.
14-
*
15+
* <p>
1516
* The algorithm doesn't take into account the distance between nodes.
1617
*
17-
* @author Jegors Čemisovs
1818
* @param <T> the type of vertex
19+
* @author Jegors Čemisovs
1920
* @since 1.0
2021
*/
2122
public class BreadthFirstSearch<T> implements SearchAlgorithm<T> {
2223

2324
@Override
2425
public List<T> findPath(Graph<T> graph, T source, T target) {
25-
var queue = new LinkedList<T>();
26+
var queue = new ArrayDeque<T>();
2627
var visited = new HashSet<T>();
2728
var previous = new HashMap<T, T>();
2829
queue.add(source);

algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package lv.id.jc.algorithm.graph;
22

3+
import java.util.ArrayDeque;
34
import java.util.HashMap;
45
import java.util.LinkedList;
56
import java.util.List;
@@ -12,15 +13,15 @@
1213
* <p>
1314
* The algorithm uses information about edge's distance to find the fastest path.
1415
*
15-
* @author Jegors Čemisovs
1616
* @param <T> the type of vertex
17+
* @author Jegors Čemisovs
1718
* @since 1.0
1819
*/
1920
public class DijkstrasAlgorithm<T> implements SearchAlgorithm<T> {
2021

2122
@Override
2223
public List<T> findPath(Graph<T> graph, T source, T target) {
23-
var queue = new LinkedList<T>();
24+
var queue = new ArrayDeque<T>();
2425
var distances = new HashMap<T, Double>();
2526
var previous = new HashMap<T, T>();
2627
queue.add(source);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* The module contains an interface for a graph and an interface for a graph search algorithm.
3+
* There is an implementation of two search algorithms:
4+
* Dijkstra's algorithm and Breadth First Search algorithm.
5+
*/
16
module lv.id.jc.algorithm.graph {
27
exports lv.id.jc.algorithm.graph;
38
}

0 commit comments

Comments
 (0)