|
1 | 1 | [](https://opensource.org/licenses/MIT) |
2 | | - |
3 | 2 |  |
4 | 3 | [](https://www.paypal.com/donate?hosted_button_id=JUP2HZ6JUPB5C) |
5 | 4 |
|
6 | 5 | # Algorithms & data structures project |
7 | 6 |
|
8 | 7 | Algorithms and data structures are fundamental to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. This repository's goal is to demonstrate how to correctly implement common data structures and algorithms in the simplest and most elegant ways. |
9 | 8 |
|
10 | | -### Other programming languages? |
11 | | - |
12 | | -This repository provides algorithm implementations in Java, however, there are other forks that provide implementations in other languages, most notably: |
13 | | - |
14 | | -* **C++/Python**: https://github.com/akzare/Algorithms |
15 | | -* **Rust**: https://github.com/TianyiShi2001/Algorithms |
16 | | - |
17 | 9 | # Running an algorithm implementation |
18 | 10 |
|
19 | | -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. |
20 | | - |
21 | | -## Running with Gradle (recommended) |
| 11 | +To compile and run any of the algorithms here, you need at least JDK version 8 and [Bazel](https://bazel.build/). |
22 | 12 |
|
23 | | -This project supports the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). The Gradle wrapper automatically downloads Gradle the first time it runs, so expect a delay when running the first command below. |
| 13 | +## Running with Bazel (recommended) |
24 | 14 |
|
25 | | -If you are on Windows, use `gradlew.bat` instead of `./gradlew` below. |
| 15 | +This project uses [Bazel](https://bazel.build/) as its build system. Install Bazel by following the [official installation guide](https://bazel.build/install). |
26 | 16 |
|
27 | 17 | Run a single algorithm like this: |
28 | 18 |
|
| 19 | +```bash |
| 20 | +bazel run //src/main/java/com/williamfiset/algorithms/<subpackage>:<ClassName> |
29 | 21 | ``` |
30 | | -./gradlew run -Palgorithm=<algorithm-subpackage>.<algorithm-class> |
31 | | -``` |
32 | | - |
33 | | -Alternatively, you can run a single algorithm specifying the full class name |
34 | 22 |
|
35 | | -``` |
36 | | -./gradlew run -Pmain=<algorithm-fully-qualified-class-name> |
| 23 | +For instance: |
37 | 24 |
|
| 25 | +```bash |
| 26 | +bazel run //src/main/java/com/williamfiset/algorithms/search:BinarySearch |
38 | 27 | ``` |
39 | 28 |
|
40 | | -For instance: |
| 29 | +Run all tests: |
41 | 30 |
|
42 | | -``` |
43 | | -./gradlew run -Palgorithm=search.BinarySearch |
| 31 | +```bash |
| 32 | +bazel test //src/test/... |
44 | 33 | ``` |
45 | 34 |
|
46 | | -or |
| 35 | +Run tests for a specific package: |
47 | 36 |
|
48 | | -``` |
49 | | -./gradlew run -Pmain=com.williamfiset.algorithms.search.BinarySearch |
| 37 | +```bash |
| 38 | +bazel test //src/test/java/com/williamfiset/algorithms/sorting:all |
50 | 39 | ``` |
51 | 40 |
|
52 | 41 | ## Compiling and running with only a JDK |
53 | 42 |
|
| 43 | +If you don't want to use Bazel, you can compile and run with just the JDK: |
| 44 | + |
54 | 45 | ### Create a classes folder |
55 | 46 |
|
56 | | -``` |
| 47 | +```bash |
57 | 48 | cd Algorithms |
58 | 49 | mkdir classes |
59 | 50 | ``` |
60 | 51 |
|
61 | 52 | ### Compile the algorithm |
62 | 53 |
|
63 | | -``` |
64 | | -javac -sourcepath src/main/java -d classes src/main/java/ <relative-path-to-java-source-file> |
| 54 | +```bash |
| 55 | +javac -sourcepath src/main/java -d classes src/main/java/<relative-path-to-java-source-file> |
65 | 56 | ``` |
66 | 57 |
|
67 | 58 | ### Run the algorithm |
68 | 59 |
|
69 | | -``` |
| 60 | +```bash |
70 | 61 | java -cp classes <class-fully-qualified-name> |
71 | 62 | ``` |
72 | 63 |
|
73 | 64 | ### Example |
74 | 65 |
|
75 | | -``` |
| 66 | +```bash |
76 | 67 | $ javac -d classes -sourcepath src/main/java src/main/java/com/williamfiset/algorithms/search/BinarySearch.java |
77 | 68 | $ java -cp classes com.williamfiset.algorithms.search.BinarySearch |
78 | 69 | ``` |
|
0 commit comments