Skip to content

Commit 7dfd917

Browse files
committed
instructions for running algorithms with JDK and Gradle
1 parent a19bfa2 commit 7dfd917

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,67 @@ Algorithms and data structures are fundamental to efficient code and good softwa
99

1010
This repository is contribution friendly :smiley:. If you'd like to add or improve an algorithm, your contribution is welcome! Please be sure to checkout the [Wiki](https://github.com/williamfiset/Algorithms/wiki) for instructions.
1111

12+
# Running an algorithm implementation
13+
14+
To compile and run any of the algorithms here, you need at least JDK version 8. Gradle can make things more convenient for you, but it is not required.
15+
16+
## Compiling and running with only a JDK
17+
18+
19+
### Create a classes folder
20+
```
21+
cd Algorithms
22+
mkdir classes
23+
```
24+
25+
### Compile the algorithm
26+
```
27+
javac -sourcepath src/main/java -d classes src/main/java/ <relative-path-to-java-source-file>
28+
```
29+
30+
### Run the algorithm
31+
```
32+
java -cp classes <class-fully-qualified-name>
33+
```
34+
35+
### Example
36+
```
37+
$ javac -d classes -sourcepath src/main/java src/main/java/com/williamfiset/algorithms/search/BinarySearch.java
38+
$ java -cp classes com.williamfiset.algorithms.search.BinarySearch
39+
```
40+
41+
## Running with Gradle
42+
43+
This project supports the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). The Gradle wrapper automatically downloads Gradle at the first time it runs, so expect a delay when running the firt command below.
44+
45+
If you are on Windows, use `gradlew.bat` instead of `./gradlew` below.
46+
47+
48+
Run a single algorithm like this:
49+
50+
```
51+
./gradlew -q run -Palgorithm=<algorithm-subpackage>.<algorithm-class>
52+
```
53+
54+
55+
Alternatively, you can run a single algorithm specifying the full class name
56+
```
57+
./gradlew -q run -Pmain=<algorithm-fully-qualified-class-name>
58+
59+
```
60+
61+
For instance:
62+
63+
```
64+
./gradlew run -Palgorithm=search.BinarySearch
65+
```
66+
67+
or
68+
69+
```
70+
./gradlew run -Pmain=com.williamfiset.algorithms.search.BinarySearch
71+
```
72+
1273
# Data Structures
1374
* [:movie_camera:](https://www.youtube.com/watch?v=q4fnJZr8ztY)[Balanced Trees](https://github.com/williamfiset/algorithms/tree/master/src/main/java/com/williamfiset/algorithms/datastructures/balancedtree)
1475
* [Avl Tree (recursive)](https://github.com/williamfiset/algorithms/tree/master/src/main/java/com/williamfiset/algorithms/datastructures/balancedtree/AVLTreeRecursive.java)

build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
apply plugin: 'java'
22
apply plugin: "com.github.sherter.google-java-format"
3+
apply plugin: 'application'
4+
5+
mainClassName = findProperty("main") ?: "com.williamfiset.algorithms.${findProperty("algorithm") ?: 'missingPackage.missingClass'}"
36

47
// https://github.com/sherter/google-java-format-gradle-plugin
58
buildscript {

0 commit comments

Comments
 (0)