From ea5a251b188f4d37dae4e1cb760b337377c2ff70 Mon Sep 17 00:00:00 2001 From: Jegors Cemisovs Date: Thu, 6 Jan 2022 19:02:24 +0200 Subject: [PATCH] Fixed issue #13 --- .../java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java | 7 ++++--- .../java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java | 5 +++-- algorithm/src/main/java/module-info.java | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java index 6c6cfa2..b7e927d 100644 --- a/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java +++ b/algorithm/src/main/java/lv/id/jc/algorithm/graph/BreadthFirstSearch.java @@ -1,5 +1,6 @@ package lv.id.jc.algorithm.graph; +import java.util.ArrayDeque; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -11,18 +12,18 @@ /** * Algorithm for finding the shortest paths between nodes in a graph. - * + *

* The algorithm doesn't take into account the distance between nodes. * - * @author Jegors Čemisovs * @param the type of vertex + * @author Jegors Čemisovs * @since 1.0 */ public class BreadthFirstSearch implements SearchAlgorithm { @Override public List findPath(Graph graph, T source, T target) { - var queue = new LinkedList(); + var queue = new ArrayDeque(); var visited = new HashSet(); var previous = new HashMap(); queue.add(source); diff --git a/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java b/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java index c6769c7..41f7817 100644 --- a/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java +++ b/algorithm/src/main/java/lv/id/jc/algorithm/graph/DijkstrasAlgorithm.java @@ -1,5 +1,6 @@ package lv.id.jc.algorithm.graph; +import java.util.ArrayDeque; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -12,15 +13,15 @@ *

* The algorithm uses information about edge's distance to find the fastest path. * - * @author Jegors Čemisovs * @param the type of vertex + * @author Jegors Čemisovs * @since 1.0 */ public class DijkstrasAlgorithm implements SearchAlgorithm { @Override public List findPath(Graph graph, T source, T target) { - var queue = new LinkedList(); + var queue = new ArrayDeque(); var distances = new HashMap(); var previous = new HashMap(); queue.add(source); diff --git a/algorithm/src/main/java/module-info.java b/algorithm/src/main/java/module-info.java index 8a8fdf6..941d8df 100644 --- a/algorithm/src/main/java/module-info.java +++ b/algorithm/src/main/java/module-info.java @@ -1,3 +1,8 @@ +/** + * The module contains an interface for a graph and an interface for a graph search algorithm. + * There is an implementation of two search algorithms: + * Dijkstra's algorithm and Breadth First Search algorithm. + */ module lv.id.jc.algorithm.graph { exports lv.id.jc.algorithm.graph; } \ No newline at end of file