This file contains information on and instructions for building1 the source code accompanying the book Beginning Algorithms, Simon Harris & James Ross, Wrox Press, 2005.
The source files are divided into two directories -- one for production classes (main
)
and one for test classes (test
) -- arranged into packages by chapter as follows:
Packages | |
---|---|
com.wrox.algorithms.iteration | Chapter 2 - Iteration and Recursion |
com.wrox.algorithms.lists | Chapter 3 - Lists |
com.wrox.algorithms.queues | Chapters 4 & 8 - Queues & Priority Queues |
com.wrox.algorithms.stacks | Chapter 5 - Stacks |
com.wrox.algorithms.sorting | Chapters 6 & 8 - Basic & Advanced Sorting |
com.wrox.algorithms.bsearch | Chapter 9 - Binary Searching |
com.wrox.algorithms.bstrees | Chapter 10 - Binary Search Trees |
com.wrox.algorithms.hashing | Chapter 11 - Hashing |
com.wrox.algorithms.sets | Chapter 12 - Sets |
com.wrox.algorithms.maps | Chapter 13 - Maps |
com.wrox.algorithms.tstrees | Chapter 14 - Ternary Search Trees |
com.wrox.algorithms.btrees | Chapter 15 - B-Trees |
com.wrox.algorithms.ssearch | Chapter 16 - String Searching |
com.wrox.algorithms.wmatch | Chapter 17 - Word Matching |
com.wrox.algorithms.geometry | Chapter 18 - Computational Geometry |
The production classes are self-contained -- they don't have any dependencies on external class libraries etc. So, to compile the production classes for Chapter 3 -- Lists -- enter the following command:
javac -sourcepath main main/com/wrox/algorithms/lists/*.java
This invokes the compiler telling it to compile all production files in the com.wrox.algorithms.lists
package.
Notice the the -sourcepath main
option. This tells the compiler where to look for any other files it may need. For example,
in this case, the code for Chapter 3 depends on the code for Chapter 2 -- Iteration and Recursion -- so the compiler needs to know
where to look to find the dependent source files.
Compiling the test classes is similar except for one thing: they depend on JUnit. So, in
order to compile the test classes, you will first need to download a copy of JUnit from
here and extract the junit.jar
file.
Once this is done, you can compile the test classes for Chapter 3 by entering the following command:
javac -classpath junit.jar -sourcepath main test/com/wrox/algorithms/lists/*.java
This invokes the compiler telling it to compile all test files in the com.wrox.algorithms.lists
package2.
Once again, notice the extra -sourcepath main
option telling the compiler where to look for any other files it may need.
Once you have the java classes compiled, you can try running some of the test cases using one of the JUnit test runners. For example,
to run the ArrayListTest
from Chapter 3 using the text-based runner, enter the following command:
java -classpath junit.jar:main:test junit.textui.TestRunner com.wrox.algorithms.lists.ArrayListTest
You should then see some output similar to the following:
......................... Time: 0.021 OK (25 tests)
This indicates that a total of 25 tests were executed in a time of 0.021 seconds and that all tests passed (OK).
For a report that uses a graphical user interface, try the following instead:
java -classpath junit.jar:main:test junit.swingui.TestRunner com.wrox.algorithms.lists.ArrayListTest
Notice the use of swingui
instead of textui
.
1Assuming you are building from the command-line. If you are using an IDE, please refer to the appropriate documentation supplied with the tool.
3Interestingly, compiling the test classess in this way also compiles the production classes as well, enabling you to quickly compile both in one go.