diff --git a/.gitignore b/.gitignore index 8866ede..0a6bfdb 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,14 @@ /Algorithms/Graph/Dijkstra/dist/ /DataStructures/BinaryTree/dist/ /Algorithms/Search/BinarySearch/nbproject/private/ -/Algorithms/Search/BinarySearch/build/ \ No newline at end of file +/Algorithms/Search/BinarySearch/build/ +/Algorithms/Search/BreadthFirstSearch/build/ +/Algorithms/Search/BreadthFirstSearch/nbproject/private/ +/Algorithms/Search/DepthFirstSearch/build/ +/Algorithms/Search/DepthFirstSearch/nbproject/private/ +/Algorithms/Traversal/BreadthFirstTraverse/nbproject/private/ +/Algorithms/Traversal/DepthFirstTraverse/nbproject/private/ +/Algorithms/Traversal/BreadthFirstTraverse/build/ +/Algorithms/Traversal/DepthFirstTraverse/build/ +/Algorithms/Sort/CountingSort/nbproject/private/ +/Algorithms/Sort/CountingSort/build/ \ No newline at end of file diff --git a/Algorithms/Traversal/DepthFirstSearch/build/classes/.netbeans_automatic_build b/Algorithms/Graph/Dijkstra/build/classes/.netbeans_automatic_build similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/build/classes/.netbeans_automatic_build rename to Algorithms/Graph/Dijkstra/build/classes/.netbeans_automatic_build diff --git a/Algorithms/Traversal/DepthFirstSearch/build/classes/.netbeans_update_resources b/Algorithms/Graph/Dijkstra/build/classes/.netbeans_update_resources similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/build/classes/.netbeans_update_resources rename to Algorithms/Graph/Dijkstra/build/classes/.netbeans_update_resources diff --git a/Algorithms/Traversal/DepthFirstSearch/build/test/classes/.netbeans_automatic_build b/Algorithms/Graph/Dijkstra/build/test/classes/.netbeans_automatic_build similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/build/test/classes/.netbeans_automatic_build rename to Algorithms/Graph/Dijkstra/build/test/classes/.netbeans_automatic_build diff --git a/Algorithms/Traversal/DepthFirstSearch/build/test/classes/.netbeans_update_resources b/Algorithms/Graph/Dijkstra/build/test/classes/.netbeans_update_resources similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/build/test/classes/.netbeans_update_resources rename to Algorithms/Graph/Dijkstra/build/test/classes/.netbeans_update_resources diff --git a/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/DijkstraTest.class b/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/DijkstraTest.class new file mode 100644 index 0000000..b92236c Binary files /dev/null and b/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/DijkstraTest.class differ diff --git a/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/sample.PNG b/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/sample.PNG new file mode 100644 index 0000000..ac49dbe Binary files /dev/null and b/Algorithms/Graph/Dijkstra/build/test/classes/dijkstra/sample.PNG differ diff --git a/Algorithms/Graph/Dijkstra/test/dijkstra/sample.PNG b/Algorithms/Graph/Dijkstra/test/dijkstra/sample.PNG new file mode 100644 index 0000000..ac49dbe Binary files /dev/null and b/Algorithms/Graph/Dijkstra/test/dijkstra/sample.PNG differ diff --git a/Algorithms/README.md b/Algorithms/README.md index e163b54..49f0918 100644 --- a/Algorithms/README.md +++ b/Algorithms/README.md @@ -2,9 +2,13 @@ ## List of projects ## 1. [Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal) - 1. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstSearch) - 2. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstSearch) + 1. [Breadth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstTraverse) + 2. [Depth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstTraverse) 2. [Graph](https://github.com/yashshah03/Java/tree/master/Algorithms/Graph) 1. [Dijkstra's Single-Source Shortest Path](https://github.com/yashshah03/Java/tree/master/Algorithms/Graph/Dijkstra) 3. [Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search) - 1. [Binary Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BinarySearch) \ No newline at end of file + 1. [Binary Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BinarySearch) + 2. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BreadthFirstSearch) + 3. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/DepthFirstSearch) +4. [Sort](https://github.com/yashshah03/Java/tree/master/Algorithms/Sort) + 1. [Counting Sort](https://github.com/yashshah03/Java/tree/master/Algorithms/Sort/CountingSort) \ No newline at end of file diff --git a/Algorithms/Traversal/BreadthFirstSearch/README.md b/Algorithms/Search/BreadthFirstSearch/README.md similarity index 83% rename from Algorithms/Traversal/BreadthFirstSearch/README.md rename to Algorithms/Search/BreadthFirstSearch/README.md index 712a3eb..4e888fe 100644 --- a/Algorithms/Traversal/BreadthFirstSearch/README.md +++ b/Algorithms/Search/BreadthFirstSearch/README.md @@ -5,7 +5,5 @@ and [Queue](https://github.com/yashshah03/Java/tree/master/DataStructures/Queue) as the base DataStructure._** ## Methods: - - setGraph(Graph) - * Set the graph to use the BFS algorithm on - - search(value) + - search(graph, value) * Breadth First Search for the given value in the graph \ No newline at end of file diff --git a/Algorithms/Traversal/BreadthFirstSearch/build.xml b/Algorithms/Search/BreadthFirstSearch/build.xml similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/build.xml rename to Algorithms/Search/BreadthFirstSearch/build.xml diff --git a/Algorithms/Traversal/BreadthFirstSearch/manifest.mf b/Algorithms/Search/BreadthFirstSearch/manifest.mf similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/manifest.mf rename to Algorithms/Search/BreadthFirstSearch/manifest.mf diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/build-impl.xml b/Algorithms/Search/BreadthFirstSearch/nbproject/build-impl.xml similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/nbproject/build-impl.xml rename to Algorithms/Search/BreadthFirstSearch/nbproject/build-impl.xml diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/genfiles.properties b/Algorithms/Search/BreadthFirstSearch/nbproject/genfiles.properties similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/nbproject/genfiles.properties rename to Algorithms/Search/BreadthFirstSearch/nbproject/genfiles.properties diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/project.properties b/Algorithms/Search/BreadthFirstSearch/nbproject/project.properties similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/nbproject/project.properties rename to Algorithms/Search/BreadthFirstSearch/nbproject/project.properties diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/project.xml b/Algorithms/Search/BreadthFirstSearch/nbproject/project.xml similarity index 100% rename from Algorithms/Traversal/BreadthFirstSearch/nbproject/project.xml rename to Algorithms/Search/BreadthFirstSearch/nbproject/project.xml diff --git a/Algorithms/Traversal/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java b/Algorithms/Search/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java similarity index 76% rename from Algorithms/Traversal/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java rename to Algorithms/Search/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java index 98b7813..58f396f 100644 --- a/Algorithms/Traversal/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java +++ b/Algorithms/Search/BreadthFirstSearch/src/breadthfirstsearch/BreadthFirstSearch.java @@ -1,5 +1,6 @@ package breadthfirstsearch; +import customexception.CustomException; import graph.Edge; import graph.Graph; import java.util.ArrayList; @@ -12,30 +13,20 @@ */ public class BreadthFirstSearch { - - private Graph graph = new Graph(); - private HashSet visited = new HashSet<>(); - - /** - * Set a Graph - * - * @param graph Graph to be used - */ - public void setGraph(Graph graph) - { - this.graph = graph; - } - /** * Search for a value in the graph * + * @param graph Graph to search the value in * @param value value to search * @return True if found, false otherwise */ - public boolean search(String value) + public static boolean + search(Graph graph, String value) { + HashSet visited = new HashSet<>(); + Queue nodes = new Queue<>(); - String current = this.graph.getNodes().get(0).getValue(); + String current = graph.getNodes().get(0).getValue(); // Push current node to the stack nodes.enqueue(current); // Add current node to visited set @@ -51,7 +42,7 @@ public boolean search(String value) try { // Get adjecency - ArrayList adjecency = this.graph.getEdges(current); + ArrayList adjecency = graph.getEdges(current); // Traverse through all adjecency edges // Put all adjecent nodes in stack, if not visited for(Edge e: adjecency) @@ -66,7 +57,7 @@ public boolean search(String value) } } } - catch(Exception e) + catch(CustomException e) { System.err.println("[ERROR] " + e.getMessage()); } diff --git a/Algorithms/Traversal/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java b/Algorithms/Search/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java similarity index 90% rename from Algorithms/Traversal/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java rename to Algorithms/Search/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java index c9e0285..dc27e7b 100644 --- a/Algorithms/Traversal/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java +++ b/Algorithms/Search/BreadthFirstSearch/test/breadthfirstsearch/BreadthFirstSearchTest.java @@ -23,12 +23,10 @@ public class BreadthFirstSearchTest public void testSearch() { System.out.println("search"); - BreadthFirstSearch instance = new BreadthFirstSearch(); Graph g = createNewGraph(); - instance.setGraph(g); - assertEquals(true, instance.search("Honolulu")); - assertEquals(false, instance.search("New York")); - assertEquals(false, instance.search("Boston")); + assertEquals(true, BreadthFirstSearch.search(g, "Honolulu")); + assertEquals(false, BreadthFirstSearch.search(g, "New York")); + assertEquals(true, BreadthFirstSearch.search(g, "Astana")); } private Graph diff --git a/Algorithms/Traversal/DepthFirstSearch/README.md b/Algorithms/Search/DepthFirstSearch/README.md similarity index 83% rename from Algorithms/Traversal/DepthFirstSearch/README.md rename to Algorithms/Search/DepthFirstSearch/README.md index 827fc94..b990fe8 100644 --- a/Algorithms/Traversal/DepthFirstSearch/README.md +++ b/Algorithms/Search/DepthFirstSearch/README.md @@ -5,8 +5,6 @@ and [Stack](https://github.com/yashshah03/Java/tree/master/DataStructures/Stack) as the base DataStructure._** ## Methods: - - setGraph(Graph) - * Set the graph to use the DFS algorithm on - - search(value) + - search(graph, value) * Depth First Search for the given value in the graph \ No newline at end of file diff --git a/Algorithms/Traversal/DepthFirstSearch/build.xml b/Algorithms/Search/DepthFirstSearch/build.xml similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/build.xml rename to Algorithms/Search/DepthFirstSearch/build.xml diff --git a/Algorithms/Traversal/DepthFirstSearch/manifest.mf b/Algorithms/Search/DepthFirstSearch/manifest.mf similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/manifest.mf rename to Algorithms/Search/DepthFirstSearch/manifest.mf diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/build-impl.xml b/Algorithms/Search/DepthFirstSearch/nbproject/build-impl.xml similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/nbproject/build-impl.xml rename to Algorithms/Search/DepthFirstSearch/nbproject/build-impl.xml diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/genfiles.properties b/Algorithms/Search/DepthFirstSearch/nbproject/genfiles.properties similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/nbproject/genfiles.properties rename to Algorithms/Search/DepthFirstSearch/nbproject/genfiles.properties diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/project.properties b/Algorithms/Search/DepthFirstSearch/nbproject/project.properties similarity index 95% rename from Algorithms/Traversal/DepthFirstSearch/nbproject/project.properties rename to Algorithms/Search/DepthFirstSearch/nbproject/project.properties index fdb14d0..4f50981 100644 --- a/Algorithms/Traversal/DepthFirstSearch/nbproject/project.properties +++ b/Algorithms/Search/DepthFirstSearch/nbproject/project.properties @@ -37,6 +37,7 @@ endorsed.classpath= excludes= file.reference.CustomException.jar=..\\..\\CustomException\\dist\\CustomException.jar file.reference.Graph.jar=..\\..\\DataStructures\\Graph\\dist\\Graph.jar +file.reference.Graph.jar-1=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Graph\\dist\\Graph.jar file.reference.hamcrest-core-1.3.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\hamcrest-core-1.3.jar file.reference.junit-4.12.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\junit-4.12.jar file.reference.LinkedList.jar=..\\..\\DataStructures\\LinkedList\\dist\\LinkedList.jar @@ -49,7 +50,8 @@ javac.classpath=\ ${file.reference.Graph.jar}:\ ${file.reference.Stack.jar}:\ ${file.reference.CustomException.jar}:\ - ${file.reference.LinkedList.jar} + ${file.reference.LinkedList.jar}:\ + ${file.reference.Graph.jar-1} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/project.xml b/Algorithms/Search/DepthFirstSearch/nbproject/project.xml similarity index 100% rename from Algorithms/Traversal/DepthFirstSearch/nbproject/project.xml rename to Algorithms/Search/DepthFirstSearch/nbproject/project.xml diff --git a/Algorithms/Traversal/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java b/Algorithms/Search/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java similarity index 76% rename from Algorithms/Traversal/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java rename to Algorithms/Search/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java index 882f255..a1bfad6 100644 --- a/Algorithms/Traversal/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java +++ b/Algorithms/Search/DepthFirstSearch/src/depthfirstsearch/DepthFirstSearch.java @@ -1,5 +1,6 @@ package depthfirstsearch; +import customexception.CustomException; import graph.Edge; import graph.Graph; import java.util.ArrayList; @@ -12,30 +13,20 @@ */ public class DepthFirstSearch { - private Graph graph = new Graph(); - private HashSet visited = new HashSet<>(); - /** - * Set a Graph - * - * @param graph Graph to be used - */ - public void setGraph(Graph graph) - { - this.graph = graph; - } - - - /** * Search for a value in the graph * + * @param graph Graph to search the value in * @param value value to search * @return True if found, false otherwise */ - public boolean search(String value) + public static boolean + search(Graph graph, String value) { + HashSet visited = new HashSet<>(); + Stack nodes = new Stack<>(); - String current = this.graph.getNodes().get(0).getValue(); + String current = graph.getNodes().get(0).getValue(); // Push current node to the stack nodes.push(current); // Add current node to visited set @@ -51,7 +42,7 @@ public boolean search(String value) try { // Get adjecency - ArrayList adjecency = this.graph.getEdges(current); + ArrayList adjecency = graph.getEdges(current); // Traverse through all adjecency edges // Put all adjecent nodes in stack, if not visited for(Edge e: adjecency) @@ -66,7 +57,7 @@ public boolean search(String value) } } } - catch(Exception e) + catch(CustomException e) { System.err.println("[ERROR] " + e.getMessage()); } diff --git a/Algorithms/Traversal/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java b/Algorithms/Search/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java similarity index 90% rename from Algorithms/Traversal/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java rename to Algorithms/Search/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java index b32a61a..8d316ae 100644 --- a/Algorithms/Traversal/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java +++ b/Algorithms/Search/DepthFirstSearch/test/depthfirstsearch/DepthFirstSearchTest.java @@ -22,12 +22,10 @@ public class DepthFirstSearchTest @Test public void testSearch() { System.out.println("search"); - DepthFirstSearch instance = new DepthFirstSearch(); Graph g = createNewGraph(); - instance.setGraph(g); - assertEquals(true, instance.search("Honolulu")); - assertEquals(false, instance.search("New York")); - assertEquals(false, instance.search("Boston")); + assertEquals(true, DepthFirstSearch.search(g, "Honolulu")); + assertEquals(false, DepthFirstSearch.search(g, "New York")); + assertEquals(true, DepthFirstSearch.search(g, "Astana")); } private Graph diff --git a/Algorithms/Search/README.md b/Algorithms/Search/README.md index 3adeb7f..c2ef6a9 100644 --- a/Algorithms/Search/README.md +++ b/Algorithms/Search/README.md @@ -2,3 +2,5 @@ ## List of projects ## 1. [Binary Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BinarySearch) +2. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BreadthFirstSearch) +3. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/DepthFirstSearch) diff --git a/Algorithms/Sort/CountingSort/README.md b/Algorithms/Sort/CountingSort/README.md new file mode 100644 index 0000000..46a93d0 --- /dev/null +++ b/Algorithms/Sort/CountingSort/README.md @@ -0,0 +1,7 @@ +## This project contains sample implementation of Counting Sort on a char array in java + **The project is developed using Apache Netbeans IDE 10.0, Java 8, Windows 10** + +## Methods: + - sort(input) + * Sort given input array in Ascending format + \ No newline at end of file diff --git a/Algorithms/Sort/CountingSort/build.xml b/Algorithms/Sort/CountingSort/build.xml new file mode 100644 index 0000000..8b2c74d --- /dev/null +++ b/Algorithms/Sort/CountingSort/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project CountingSort. + + + diff --git a/Algorithms/Sort/CountingSort/manifest.mf b/Algorithms/Sort/CountingSort/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Algorithms/Sort/CountingSort/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Algorithms/Sort/CountingSort/nbproject/build-impl.xml b/Algorithms/Sort/CountingSort/nbproject/build-impl.xml new file mode 100644 index 0000000..e6f0461 --- /dev/null +++ b/Algorithms/Sort/CountingSort/nbproject/build-impl.xml @@ -0,0 +1,1768 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Algorithms/Sort/CountingSort/nbproject/genfiles.properties b/Algorithms/Sort/CountingSort/nbproject/genfiles.properties new file mode 100644 index 0000000..83df776 --- /dev/null +++ b/Algorithms/Sort/CountingSort/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=15efb29d +build.xml.script.CRC32=ab62d428 +build.xml.stylesheet.CRC32=f85dc8f2@1.90.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=15efb29d +nbproject/build-impl.xml.script.CRC32=dd23c14c +nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.90.1.48 diff --git a/Algorithms/Sort/CountingSort/nbproject/project.properties b/Algorithms/Sort/CountingSort/nbproject/project.properties new file mode 100644 index 0000000..c9465ca --- /dev/null +++ b/Algorithms/Sort/CountingSort/nbproject/project.properties @@ -0,0 +1,99 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/CountingSort.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/CountingSort +excludes= +file.reference.hamcrest-core-1.3.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\hamcrest-core-1.3.jar +file.reference.junit-4.12.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\junit-4.12.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.hamcrest-core-1.3.jar}:\ + ${file.reference.junit-4.12.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=CountingSort +main.class=countingsort.CountingSort +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Algorithms/Sort/CountingSort/nbproject/project.xml b/Algorithms/Sort/CountingSort/nbproject/project.xml new file mode 100644 index 0000000..b522002 --- /dev/null +++ b/Algorithms/Sort/CountingSort/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + CountingSort + + + + + + + + + diff --git a/Algorithms/Sort/CountingSort/src/countingsort/CountingSort.java b/Algorithms/Sort/CountingSort/src/countingsort/CountingSort.java new file mode 100644 index 0000000..1b278ca --- /dev/null +++ b/Algorithms/Sort/CountingSort/src/countingsort/CountingSort.java @@ -0,0 +1,64 @@ +package countingsort; +/** + * + * @author Yash Shah + */ +public class CountingSort +{ + /** + * Implements counting sort for a char array + * + * @param input + * @return sorted array + */ + public static char[] + sort(char[] input) + { + // output array + char[] output = new char[input.length]; + // Auxilary array + int[] aux = new int[256]; + + // Store the occurences of chars + for(int i=0; i=0; i--) + { + char temp = input[i]; + int pos = getCharToInt(temp); + // Decrement the count at POS by 1 in AUX array + aux[pos]--; + // Put the element fron input at i in output at aux[pos] + output[aux[pos]] = temp; + } + return output; + } + + private static int + getCharToInt(char val) + { + int pos; + // If letter is uppercase + if(Character.isUpperCase(val)) + pos = val - 'A'; + else + pos = val - 'a'; + + return pos; + } +} diff --git a/Algorithms/Sort/CountingSort/test/countingsort/CountingSortTest.java b/Algorithms/Sort/CountingSort/test/countingsort/CountingSortTest.java new file mode 100644 index 0000000..5f5587b --- /dev/null +++ b/Algorithms/Sort/CountingSort/test/countingsort/CountingSortTest.java @@ -0,0 +1,28 @@ +package countingsort; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Yash Shah + */ +public class CountingSortTest +{ + /** + * Test of sort method, of class CountingSort. + */ + @Test + public void testSort() + { + System.out.println("sort"); + char[] input = {'a', 'b', 'a', 'c', 'e', 'A', 'B', 'h', 'I', 'j', 'k'}; + char[] expResult = {'a', 'a', 'A', 'b', 'B', 'c', 'e', 'h', 'I', 'j', 'k'}; + char[] result = CountingSort.sort(input); + assertArrayEquals(expResult, result); + char[] input2 = {'a', 'b', 'A', 'c', 'e', 'C', 'B', 'h', 'I', 'i', 'k'}; + char[] expResult2 = {'a', 'A', 'b', 'B', 'c', 'C', 'e', 'h', 'I', 'i', 'k'}; + char[] result2 = CountingSort.sort(input2); + assertArrayEquals(expResult2, result2); + } +} diff --git a/Algorithms/Sort/README.md b/Algorithms/Sort/README.md new file mode 100644 index 0000000..72656ad --- /dev/null +++ b/Algorithms/Sort/README.md @@ -0,0 +1,4 @@ +**This repository contains different types of sorting algorithms written in Java programming language** + +## List of projects ## +1. [Counting Sort](https://github.com/yashshah03/Java/tree/master/Algorithms/Sort/CountingSort) diff --git a/Algorithms/Traversal/BreadthFirstSearch/build/built-jar.properties b/Algorithms/Traversal/BreadthFirstSearch/build/built-jar.properties deleted file mode 100644 index d88e35d..0000000 --- a/Algorithms/Traversal/BreadthFirstSearch/build/built-jar.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Fri, 08 Feb 2019 14:27:40 -0500 - - -C\:\\Users\\yashs\\Documents\\Projects\\Java\\Algorithms\\Traversal\\BreadthFirstSearch= diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/config.properties b/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/config.properties deleted file mode 100644 index e69de29..0000000 diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.properties b/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.properties deleted file mode 100644 index 873bf84..0000000 --- a/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.properties +++ /dev/null @@ -1,12 +0,0 @@ -compile.on.save=true -do.depend=false -do.jar=true -do.jlink=false -file.reference.CustomException.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\CustomException\\dist\\CustomException.jar -file.reference.Graph.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Graph\\dist\\Graph.jar -file.reference.LinkedList.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\LinkedList\\dist\\LinkedList.jar -file.reference.Queue.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Queue\\dist\\Queue.jar -javac.debug=true -javadoc.preview=true -jlink.strip=false -user.properties.file=C:\\Users\\yashs\\AppData\\Roaming\\NetBeans\\10.0\\build.properties diff --git a/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.xml b/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.xml deleted file mode 100644 index 6807a2b..0000000 --- a/Algorithms/Traversal/BreadthFirstSearch/nbproject/private/private.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Algorithms/Traversal/BreadthFirstTraverse/README.md b/Algorithms/Traversal/BreadthFirstTraverse/README.md new file mode 100644 index 0000000..a8ba9e1 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/README.md @@ -0,0 +1,9 @@ +## This project contains sample implementation of Breadth First Traversal in java + **The project is developed using Apache Netbeans IDE 10.0, Java 8, Windows 10** + +**_This project uses my implementation of [Graph](https://github.com/yashshah03/Java/tree/master/DataStructures/Graph) +and [Queue](https://github.com/yashshah03/Java/tree/master/DataStructures/Queue) as the base DataStructure._** + +## Methods: + - traverse(graph) + * Breadth First traverse on the given graph \ No newline at end of file diff --git a/Algorithms/Traversal/BreadthFirstTraverse/build.xml b/Algorithms/Traversal/BreadthFirstTraverse/build.xml new file mode 100644 index 0000000..2f9f987 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project BreadthFirstTraverse. + + + diff --git a/Algorithms/Traversal/BreadthFirstTraverse/manifest.mf b/Algorithms/Traversal/BreadthFirstTraverse/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Algorithms/Traversal/BreadthFirstTraverse/nbproject/build-impl.xml b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/build-impl.xml new file mode 100644 index 0000000..75b8f00 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/build-impl.xml @@ -0,0 +1,1768 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Algorithms/Traversal/BreadthFirstTraverse/nbproject/genfiles.properties b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/genfiles.properties new file mode 100644 index 0000000..12a7946 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=abead4aa +build.xml.script.CRC32=0e7519ce +build.xml.stylesheet.CRC32=f85dc8f2@1.90.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=abead4aa +nbproject/build-impl.xml.script.CRC32=655c37d5 +nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.90.1.48 diff --git a/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.properties b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.properties new file mode 100644 index 0000000..2a5f332 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.properties @@ -0,0 +1,110 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=BreadthFirstTraverse +application.vendor=yashs +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BreadthFirstTraverse.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/BreadthFirstTraverse +endorsed.classpath= +excludes= +file.reference.CustomException.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\CustomException\\dist\\CustomException.jar +file.reference.Graph.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Graph\\dist\\Graph.jar +file.reference.hamcrest-core-1.3.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\hamcrest-core-1.3.jar +file.reference.junit-4.12.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\junit-4.12.jar +file.reference.LinkedList.jar=..\\..\\..\\DataStructures\\LinkedList\\dist\\LinkedList.jar +file.reference.Queue.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Queue\\dist\\Queue.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.CustomException.jar}:\ + ${file.reference.Graph.jar}:\ + ${file.reference.Queue.jar}:\ + ${file.reference.hamcrest-core-1.3.jar}:\ + ${file.reference.junit-4.12.jar}:\ + ${file.reference.LinkedList.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit_5.classpath} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=BreadthFirstTraverse +main.class=breadthfirsttraverse.BreadthFirstTraverse +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.xml b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.xml new file mode 100644 index 0000000..a5ec770 --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + BreadthFirstTraverse + + + + + + + + + diff --git a/Algorithms/Traversal/BreadthFirstTraverse/src/breadthfirsttraverse/BreadthFirstTraverse.java b/Algorithms/Traversal/BreadthFirstTraverse/src/breadthfirsttraverse/BreadthFirstTraverse.java new file mode 100644 index 0000000..8e10c3a --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/src/breadthfirsttraverse/BreadthFirstTraverse.java @@ -0,0 +1,60 @@ +package breadthfirsttraverse; + +import customexception.CustomException; +import graph.Edge; +import graph.Graph; +import java.util.ArrayList; +import java.util.HashSet; +import queue.Queue; + +/** + * + * @author Yash Shah + */ +public class BreadthFirstTraverse +{ + /** + * Traverse the graph Breadth First + * + * @param graph The graph to traverse + */ + public static void + traverse(Graph graph) + { + HashSet visited = new HashSet<>(); + + Queue nodes = new Queue<>(); + String current = graph.getNodes().get(0).getValue(); + // Push current node to the stack + nodes.enqueue(current); + // Add current node to visited set + visited.add(current); + System.out.println("CURRENT: " + current); + + while(!nodes.isEmpty()) + { + current = nodes.dequeue(); + System.out.println(current); + try + { + // Get adjecency + ArrayList adjecency = graph.getEdges(current); + // Traverse through all adjecency edges + // Put all adjecent nodes in stack, if not visited + for(Edge e: adjecency) + { + String adjecent = e.getDestination().toString(); + if(!visited.contains(adjecent)) + { + nodes.enqueue(adjecent); + visited.add(adjecent); + } + } + } + catch(CustomException e) + { + System.err.println("[ERROR] " + e.getMessage()); + } + } + } +} diff --git a/Algorithms/Traversal/BreadthFirstTraverse/test/breadthfirsttraverse/BreadthFirstTraverseTest.java b/Algorithms/Traversal/BreadthFirstTraverse/test/breadthfirsttraverse/BreadthFirstTraverseTest.java new file mode 100644 index 0000000..04a8fdf --- /dev/null +++ b/Algorithms/Traversal/BreadthFirstTraverse/test/breadthfirsttraverse/BreadthFirstTraverseTest.java @@ -0,0 +1,63 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package breadthfirsttraverse; + +import customexception.CustomException; +import graph.Graph; +import org.junit.Test; + +/** + * + * @author Yash Shah + */ +public class BreadthFirstTraverseTest +{ + /** + * Test of traverse method, of class BreadthFirstTraverse. + */ + @Test + public void testTraverse() { + BreadthFirstTraverse.traverse(createNewGraph()); + } + + private Graph + createNewGraph() + { + Graph graph = new Graph(); + try + { + graph.addUnidirectionalEdge("Astana", "Delhi", 4126); + graph.addUnidirectionalEdge("Astana", "Beijing", 4175); + graph.addUnidirectionalEdge("Astana", "Moscow", 2150); + graph.addUnidirectionalEdge("Delhi", "Singapor", 4140); + graph.addUnidirectionalEdge("Beijing", "Singapor", 4742); + graph.addUnidirectionalEdge("Beijing", "Tokyo", 2098); + graph.addUnidirectionalEdge("Moscow", "London", 2498); + graph.addUnidirectionalEdge("Moscow", "Algiers", 3336); + graph.addUnidirectionalEdge("Moscow", "Barcelona", 3006); + graph.addUnidirectionalEdge("Singapor", "Brisbane", 6152); + graph.addUnidirectionalEdge("Tokyo", "Honolulu", 6195); + graph.addUnidirectionalEdge("Tokyo", "Anchorage", 5555); + graph.addUnidirectionalEdge("London", "Boston", 5264); + graph.addUnidirectionalEdge("Algiers", "San Juan", 7015); + graph.addUnidirectionalEdge("Barcelona", "Boston", 5861); + graph.addUnidirectionalEdge("Brisbane", "Honolulu", 7566); + graph.addUnidirectionalEdge("Honolulu", "San Fransicso", 3851); + graph.addUnidirectionalEdge("Anchorage", "Vancouver", 2129); + graph.addUnidirectionalEdge("Boston", "Vancouver", 4022); + graph.addUnidirectionalEdge("San Juan", "Houston", 3178); + graph.addUnidirectionalEdge("San Juan", "Helena", 5194); + graph.addUnidirectionalEdge("San Fransicso", "Vancouver", 1276); + graph.addUnidirectionalEdge("Houston", "Vancouver", 3184); + graph.addUnidirectionalEdge("Helena", "Vancouver", 880); + } + catch (CustomException ex) + { + System.err.println(ex.getMessage()); + } + return graph; + } +} diff --git a/Algorithms/Traversal/DepthFirstSearch/build/classes/depthfirstsearch/DepthFirstSearch.class b/Algorithms/Traversal/DepthFirstSearch/build/classes/depthfirstsearch/DepthFirstSearch.class deleted file mode 100644 index f62c9fa..0000000 Binary files a/Algorithms/Traversal/DepthFirstSearch/build/classes/depthfirstsearch/DepthFirstSearch.class and /dev/null differ diff --git a/Algorithms/Traversal/DepthFirstSearch/build/test/classes/depthfirstsearch/DepthFirstSearchTest.class b/Algorithms/Traversal/DepthFirstSearch/build/test/classes/depthfirstsearch/DepthFirstSearchTest.class deleted file mode 100644 index 661197f..0000000 Binary files a/Algorithms/Traversal/DepthFirstSearch/build/test/classes/depthfirstsearch/DepthFirstSearchTest.class and /dev/null differ diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/private/config.properties b/Algorithms/Traversal/DepthFirstSearch/nbproject/private/config.properties deleted file mode 100644 index e69de29..0000000 diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.properties b/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.properties deleted file mode 100644 index f3e79fb..0000000 --- a/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.properties +++ /dev/null @@ -1,12 +0,0 @@ -compile.on.save=true -do.depend=false -do.jar=true -do.jlink=false -file.reference.CustomException.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\CustomException\\dist\\CustomException.jar -file.reference.Graph.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\CustomException\\dist\\CustomException.jar -file.reference.LinkedList.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\LinkedList\\dist\\LinkedList.jar -file.reference.Stack.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Stack\\dist\\Stack.jar -javac.debug=true -javadoc.preview=true -jlink.strip=false -user.properties.file=C:\\Users\\yashs\\AppData\\Roaming\\NetBeans\\10.0\\build.properties diff --git a/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.xml b/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.xml deleted file mode 100644 index 4750962..0000000 --- a/Algorithms/Traversal/DepthFirstSearch/nbproject/private/private.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Algorithms/Traversal/DepthFirstTraverse/README.md b/Algorithms/Traversal/DepthFirstTraverse/README.md new file mode 100644 index 0000000..4c21d7a --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/README.md @@ -0,0 +1,9 @@ +## This project contains sample implementation of Depth First Traversal in java + **The project is developed using Apache Netbeans IDE 10.0, Java 8, Windows 10** + +**_This project uses my implementation of [Graph](https://github.com/yashshah03/Java/tree/master/DataStructures/Graph) +and [Stack](https://github.com/yashshah03/Java/tree/master/DataStructures/Stack) as the base DataStructure._** + +## Methods: + - traverse(graph) + * Depth First traverse on the given graph \ No newline at end of file diff --git a/Algorithms/Traversal/DepthFirstTraverse/build.xml b/Algorithms/Traversal/DepthFirstTraverse/build.xml new file mode 100644 index 0000000..4a9ff2f --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project DepthFirstTraverse. + + + diff --git a/Algorithms/Traversal/DepthFirstTraverse/manifest.mf b/Algorithms/Traversal/DepthFirstTraverse/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Algorithms/Traversal/DepthFirstTraverse/nbproject/build-impl.xml b/Algorithms/Traversal/DepthFirstTraverse/nbproject/build-impl.xml new file mode 100644 index 0000000..0e3fcd4 --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/nbproject/build-impl.xml @@ -0,0 +1,1768 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Algorithms/Traversal/DepthFirstTraverse/nbproject/genfiles.properties b/Algorithms/Traversal/DepthFirstTraverse/nbproject/genfiles.properties new file mode 100644 index 0000000..436fa7e --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=626fba0e +build.xml.script.CRC32=a3ac841b +build.xml.stylesheet.CRC32=f85dc8f2@1.90.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=626fba0e +nbproject/build-impl.xml.script.CRC32=ee1df144 +nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.90.1.48 diff --git a/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.properties b/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.properties new file mode 100644 index 0000000..b5b85ed --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.properties @@ -0,0 +1,109 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=DepthFirstTraverse +application.vendor=yashs +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/DepthFirstTraverse.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/DepthFirstTraverse +endorsed.classpath= +excludes= +file.reference.CustomException.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\CustomException\\dist\\CustomException.jar +file.reference.Graph.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Graph\\dist\\Graph.jar +file.reference.hamcrest-core-1.3.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\hamcrest-core-1.3.jar +file.reference.junit-4.12.jar=C:\\Users\\yashs\\Documents\\netbeans\\platform\\modules\\ext\\junit-4.12.jar +file.reference.LinkedList.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\LinkedList\\dist\\LinkedList.jar +file.reference.Stack.jar=C:\\Users\\yashs\\Documents\\Projects\\Java\\DataStructures\\Stack\\dist\\Stack.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.Graph.jar}:\ + ${file.reference.Stack.jar}:\ + ${file.reference.CustomException.jar}:\ + ${file.reference.LinkedList.jar}:\ + ${file.reference.hamcrest-core-1.3.jar}:\ + ${file.reference.junit-4.12.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=DepthFirstTraverse +main.class=depthfirsttraverse.DepthFirstTraverse +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.xml b/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.xml new file mode 100644 index 0000000..16e3e2c --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + DepthFirstTraverse + + + + + + + + + diff --git a/Algorithms/Traversal/DepthFirstTraverse/src/depthfirsttraverse/DepthFirstTraverse.java b/Algorithms/Traversal/DepthFirstTraverse/src/depthfirsttraverse/DepthFirstTraverse.java new file mode 100644 index 0000000..b6cb228 --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/src/depthfirsttraverse/DepthFirstTraverse.java @@ -0,0 +1,58 @@ +package depthfirsttraverse; + +import customexception.CustomException; +import graph.Edge; +import graph.Graph; +import java.util.ArrayList; +import java.util.HashSet; +import stack.Stack; + +/** + * + * @author Yash Shah + */ +public class DepthFirstTraverse +{ + /** + * Traverse the graph Depth First + * + */ + public static void + traverse(Graph graph) + { + HashSet visited = new HashSet<>(); + + Stack nodes = new Stack<>(); + String current = graph.getNodes().get(0).getValue(); + // Push current node to the stack + nodes.push(current); + // Add current node to visited set + visited.add(current); + + while(!nodes.isEmpty()) + { + current = nodes.pop(); + System.out.println(current); + try + { + // Get adjecency + ArrayList adjecency = graph.getEdges(current); + // Traverse through all adjecency edges + // Put all adjecent nodes in stack, if not visited + for(Edge e: adjecency) + { + String adjecent = e.getDestination().toString(); + if(!visited.contains(adjecent)) + { + nodes.push(adjecent); + visited.add(adjecent); + } + } + } + catch(CustomException e) + { + System.err.println("[ERROR] " + e.getMessage()); + } + } + } +} diff --git a/Algorithms/Traversal/DepthFirstTraverse/test/depthfirsttraverse/DepthFirstTraverseTest.java b/Algorithms/Traversal/DepthFirstTraverse/test/depthfirsttraverse/DepthFirstTraverseTest.java new file mode 100644 index 0000000..caf4786 --- /dev/null +++ b/Algorithms/Traversal/DepthFirstTraverse/test/depthfirsttraverse/DepthFirstTraverseTest.java @@ -0,0 +1,65 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package depthfirsttraverse; + +import customexception.CustomException; +import graph.Graph; +import org.junit.Test; + +/** + * + * @author Yash Shah + */ +public class DepthFirstTraverseTest +{ + /** + * Test of traverse method, of class DepthFirstTraverse. + */ + @Test + public void testTraverse() + { + System.out.println("traverse"); + DepthFirstTraverse.traverse(createNewGraph()); + } + + private Graph + createNewGraph() + { + Graph graph = new Graph(); + try + { + graph.addUnidirectionalEdge("Astana", "Delhi", 4126); + graph.addUnidirectionalEdge("Astana", "Beijing", 4175); + graph.addUnidirectionalEdge("Astana", "Moscow", 2150); + graph.addUnidirectionalEdge("Delhi", "Singapor", 4140); + graph.addUnidirectionalEdge("Beijing", "Singapor", 4742); + graph.addUnidirectionalEdge("Beijing", "Tokyo", 2098); + graph.addUnidirectionalEdge("Moscow", "London", 2498); + graph.addUnidirectionalEdge("Moscow", "Algiers", 3336); + graph.addUnidirectionalEdge("Moscow", "Barcelona", 3006); + graph.addUnidirectionalEdge("Singapor", "Brisbane", 6152); + graph.addUnidirectionalEdge("Tokyo", "Honolulu", 6195); + graph.addUnidirectionalEdge("Tokyo", "Anchorage", 5555); + graph.addUnidirectionalEdge("London", "Boston", 5264); + graph.addUnidirectionalEdge("Algiers", "San Juan", 7015); + graph.addUnidirectionalEdge("Barcelona", "Boston", 5861); + graph.addUnidirectionalEdge("Brisbane", "Honolulu", 7566); + graph.addUnidirectionalEdge("Honolulu", "San Fransicso", 3851); + graph.addUnidirectionalEdge("Anchorage", "Vancouver", 2129); + graph.addUnidirectionalEdge("Boston", "Vancouver", 4022); + graph.addUnidirectionalEdge("San Juan", "Houston", 3178); + graph.addUnidirectionalEdge("San Juan", "Helena", 5194); + graph.addUnidirectionalEdge("San Fransicso", "Vancouver", 1276); + graph.addUnidirectionalEdge("Houston", "Vancouver", 3184); + graph.addUnidirectionalEdge("Helena", "Vancouver", 880); + } + catch (CustomException ex) + { + System.err.println(ex.getMessage()); + } + return graph; + } +} diff --git a/Algorithms/Traversal/README.md b/Algorithms/Traversal/README.md index 70ce62f..5eca657 100644 --- a/Algorithms/Traversal/README.md +++ b/Algorithms/Traversal/README.md @@ -1,5 +1,5 @@ **This repository contains different types of traversal algorithms written in Java programming language** ## List of projects ## -1. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstSearch) -2. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstSearch) +1. [Breadth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstTraverse) +2. [Depth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstTraverse) diff --git a/DataStructures/Graph/src/graph/Graph.java b/DataStructures/Graph/src/graph/Graph.java index d2b991d..f043659 100644 --- a/DataStructures/Graph/src/graph/Graph.java +++ b/DataStructures/Graph/src/graph/Graph.java @@ -1,11 +1,10 @@ package graph; -import java.util.HashMap; import java.util.Map; - import customexception.CustomException; import java.util.ArrayList; import java.util.HashSet; +import java.util.LinkedHashMap; /** * @@ -19,9 +18,10 @@ public class Graph public Graph() { - edgeList = new HashMap(); - nodeList = new HashMap(); - srcDstList = new HashMap(); + // Using linkedHashMap instead of HashMap to keep insertion order + edgeList = new LinkedHashMap(); + nodeList = new LinkedHashMap(); + srcDstList = new LinkedHashMap(); } /** @@ -332,7 +332,6 @@ public Graph() nodeList.values().forEach((node) -> { nodes.add(node); }); - return nodes; } diff --git a/DataStructures/Graph/test/graph/GraphTest.java b/DataStructures/Graph/test/graph/GraphTest.java index daf0f28..1a14d61 100644 --- a/DataStructures/Graph/test/graph/GraphTest.java +++ b/DataStructures/Graph/test/graph/GraphTest.java @@ -505,4 +505,41 @@ public void testPrintNodes() }); instance.printNodes(); } + + /** + * Test of getNodes method, of class Graph. + * + */ + @Test + public void testGetNodes() + { + System.out.println("getNodes"); + Graph graph = new Graph(); + ArrayList list = new ArrayList(Arrays.asList("D-A-5", + "B-F-6", + "C-E-7", + "E-F-8", + "A-B-2", + "A-C-3", + "A-D-4", + "D-F-9")); + list.forEach((w) -> { + String[] places = w.split("-"); + try + { + graph.addUnidirectionalEdge(places[0], + places[1], + Integer.parseInt(places[2])); + } + catch (CustomException ex) + { + System.err.println("testGetNodes: " + ex.getMessage()); + } + }); + ArrayList nodes = graph.getNodes(); + nodes.forEach((node)->{ + System.out.print(node.getValue() + " - "); + }); + System.out.println(); + } } diff --git a/README.md b/README.md index f602a44..7c2370d 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,13 @@ 2. [Custom Exception](https://github.com/yashshah03/Java/tree/master/CustomException) 3. [Algorithms](https://github.com/yashshah03/Java/tree/master/Algorithms) 1. [Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal) - 1. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstSearch) - 2. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstSearch) + 1. [Breadth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirstTraverse) + 2. [Depth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirstTraverse) 2. [Graph](https://github.com/yashshah03/Java/tree/master/Algorithms/Graph) 1. [Dijkstra's Single-Source Shortest Path](https://github.com/yashshah03/Java/tree/master/Algorithms/Graph/Dijkstra) 3. [Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search) 1. [Binary Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BinarySearch) + 2. [Breadth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/BreadthFirstSearch) + 3. [Depth First Search](https://github.com/yashshah03/Java/tree/master/Algorithms/Search/DepthFirstSearch) + 4. [Sort](https://github.com/yashshah03/Java/tree/master/Algorithms/Sort) + 1. [Counting Sort](https://github.com/yashshah03/Java/tree/master/Algorithms/Sort/CountingSort)