Data Structures, Algorithms, & Applications in Java
Sartaj Sahni

Downloading and Using The Codes

Downloading
  1. Download the zip file into a directory (say) codes.
  2. Unzip the zip file you have downloaded. This will create subdirectories codes\dataStructures, c:\codes\applications, codes\wrappers, etc. and many html files in the directory codes.
  3. Browse the html files (start with ProgramIndex.htm and index.html) using a net browser to get a feel for where different source and compiled codes are.
  4. The file name for a source code is ClassName.java, and the file name for the compiled code is ClassName.class. The *.class files were obtained by using the Java 1.2 compiler. Sample input for programs that require input is in the file ClassName.input. The output the program should produce is in the file ClassName.output. To successfully recompile the codes you have downloaded, you must use Java 1.2 or higher. The codes in the text as well as those you download from here employ the interface Computable (Section 1.13.1), which is in the package utilities. This interface is extended by the interface Operable (Section 1.13.4). If you are using Java 1.5, you will run into problems because Java 1.5 defines its own interface Computable. Java 1.5 users should rename Computable to MyComputable, wherever Computable is used in the codes you download.
  5. You can download Java documentation as well as the latest Java compiler and a variety of IDEs from www.javasoft.com:80/products/jdk Follow the links to Java 2 SDK Version 1.2.x or Version 1.3.x.


Using the Codes
  1. DOS Users
    You may compile a program from DOS as below (the current directory is the directory c:\codes into which you downloaded and later unzipped the text programs).
    javac dataStructures\ArrayLinearList.java
    You may run a compiled program from DOS using a command such as:
    java dataStructures.ArrayLinearList
    A program applications.MyProgram that takes input from a file inputFile and whose output you wish to save in the file outputFile may be run as below:
    java applications.MyProgram <inputFile >outputFile
    To compile and run from other directories, set the classpath environment variable as below:
    set classpath=.;c:\codes;c:\other1;c:\other2\subother2
    This causes the Java compiler and interpreter to look in the stated directories for packages, source and compiled codes. Add the above classpath statement to your autoexec.bat file if you are using Windows 98 or an earlier version of Windows.
    If you are using Windows NT, do the following:

    Open the Windows Control Panel for System.
    (Start->Settings->Ctrl.Panel)
    Choose the Environment tab and go to User variables. Add the full path to the directory (e.g., c:\codes) to the end of the CLASSPATH variable, using a semicolon as a separator. If you do not have a CLASSPATH defined, create one and set it equal to this path.

    If you are using Windows 2000 or XP, do the following:

    Open the Windows Control Panel for System.
    Choose the Advanced tab and click the Environment Variables button.
    Add the full path to the directory (e.g., c:\codes) to the end of the CLASSPATH variable, using a semicolon as a separator. If you do not have a CLASSPATH defined, create one and set it equal to c:\codes.

    In case you haven't already done so, you should add the path to your Java compiler (e.g., c:\jdk1.3\bin) to the PATH environment variable using a process such as that just described for the CLASSPATH environment vairable.

  2. Kawa, jGrasp, and pcGrasp Users
    You can use SUN's JDK through Windows95/98/00/NT by downloading a program such as Kawa from
    www.text-tools.com/kawa (set CLASSPATH and PATH) as above)

    or jGrasp from
    http://www.eng.auburn.edu/department/cse/research/grasp/ftp_information.html (set CLASSPATH and PATH as above)

    or pcGrasp from
    http://www.eng.auburn.edu/department/cse/research/grasp/ftp_information.html. (set CLASSPATH and PATH as follows: start pcGrasp, select (i.e., click your mouse here) File, select GlobalPreferences, select Workspace/Compiler, select the Java compiler you will use, select Edit, select CLASSPATH, select Edit, set value of variable to .;c:\codes (or to something more elaborate as described above for DOS), repeat for PATH, select Save, select Save, select OK, exit from pcGrasp, restart pcGrasp.

    If pcgrasp refuses to run your programs in its own environment after you have set the classpath as above, then you need to add, with the windows semicolon (';') separator, the default class paths that are normally used by the Java Virtual Machine: these involve the paths to (1) the lib subdirectory of the jdkx.x.x directory in which you have your jdk installed (make sure it is the lib of the jdk, and NOT the lib of some runtime environment which comes as an additional tool and which is somewhere deeper); to (2) the classes.zip archive which resides (either per se or hidden under some Tools.jar archive) in the above described lib directory. If, say, you have downloaded jdk1.3.1 in a directory called c:\jdk1.3.1, then you should add to your classpath:
    ;c:\jdk1.3.1\lib;c:\jdk1.3.1\classes;
    c:\jdk1.3.1\lib\classes.zip;c:\jdk1.3.1\lib\classes;
    Note: it does not hurt (other than some improbable naming conflicts) to add more alternatives to your classpath list of choices. The Sun website (http://java.sun.com/products/jdk/1.1/docs/tooldocs/win32/classpath.html) mentions the second alternative above (we have included it because it may be necessary for some older java versions; the last alternative is for the case in which your classes have ended up under your lib directory).

    An introduction to pcGrasp is avialable from http://www.eng.auburn.edu/department/cse/research/grasp/documentation/ intro_to_GRASP/pcgrasp/index.html.

  3. UNIX Users
    On UNIX systems you should set CLASSPATH in your .cshrc file by adding the following line:
    setenv CLASSPATH .:$HOME/codes
    You can also use the Grasp environment. See above.