From 4ed3aa9db9f5a4190550eee0343384237523d8ce Mon Sep 17 00:00:00 2001 From: Yash Shah <45716936+yashshah03@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:09:45 -0500 Subject: [PATCH 1/2] Update README.md --- Algorithms/Traversal/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Algorithms/Traversal/README.md b/Algorithms/Traversal/README.md index e551253..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 Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/BreadthFirst) -2. [Depth First Traversal](https://github.com/yashshah03/Java/tree/master/Algorithms/Traversal/DepthFirst) +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) From 12ec0aceb4163d8e23c6b5f449a39fdc1218883a Mon Sep 17 00:00:00 2001 From: Yash Shah Date: Sat, 16 Feb 2019 18:07:59 -0500 Subject: [PATCH 2/2] Implement Counting Sort --- .gitignore | 4 +- Algorithms/README.md | 4 +- Algorithms/Sort/CountingSort/README.md | 7 + Algorithms/Sort/CountingSort/build.xml | 73 + Algorithms/Sort/CountingSort/manifest.mf | 3 + .../CountingSort/nbproject/build-impl.xml | 1768 +++++++++++++++++ .../nbproject/genfiles.properties | 8 + .../CountingSort/nbproject/project.properties | 99 + .../Sort/CountingSort/nbproject/project.xml | 15 + .../src/countingsort/CountingSort.java | 64 + .../test/countingsort/CountingSortTest.java | 28 + Algorithms/Sort/README.md | 4 + README.md | 2 + 13 files changed, 2077 insertions(+), 2 deletions(-) create mode 100644 Algorithms/Sort/CountingSort/README.md create mode 100644 Algorithms/Sort/CountingSort/build.xml create mode 100644 Algorithms/Sort/CountingSort/manifest.mf create mode 100644 Algorithms/Sort/CountingSort/nbproject/build-impl.xml create mode 100644 Algorithms/Sort/CountingSort/nbproject/genfiles.properties create mode 100644 Algorithms/Sort/CountingSort/nbproject/project.properties create mode 100644 Algorithms/Sort/CountingSort/nbproject/project.xml create mode 100644 Algorithms/Sort/CountingSort/src/countingsort/CountingSort.java create mode 100644 Algorithms/Sort/CountingSort/test/countingsort/CountingSortTest.java create mode 100644 Algorithms/Sort/README.md diff --git a/.gitignore b/.gitignore index 1e00b42..0a6bfdb 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,6 @@ /Algorithms/Traversal/BreadthFirstTraverse/nbproject/private/ /Algorithms/Traversal/DepthFirstTraverse/nbproject/private/ /Algorithms/Traversal/BreadthFirstTraverse/build/ -/Algorithms/Traversal/DepthFirstTraverse/build/ \ No newline at end of file +/Algorithms/Traversal/DepthFirstTraverse/build/ +/Algorithms/Sort/CountingSort/nbproject/private/ +/Algorithms/Sort/CountingSort/build/ \ No newline at end of file diff --git a/Algorithms/README.md b/Algorithms/README.md index 348992d..49f0918 100644 --- a/Algorithms/README.md +++ b/Algorithms/README.md @@ -9,4 +9,6 @@ 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) \ No newline at end of file + 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/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/README.md b/README.md index 779d6b7..7c2370d 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,5 @@ 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)