
The Sort Library is a set of sorting algorithms written in
Java:
- QuickSort - the fastest sorting algorithm in the general
case.
- HeapSort - a fairly fast, complex sorting algorithm using
binary trees.
- InsertionSort - a slow but stable sorting algorithm, which
beats QuickSort in the almost sorted case.
- BubbleSort - a slow but very stable sorting algorithm, the
fastest algorithm in the almost sorted or sorted case.
Each class takes a group of items, and sorts it in ascending
order. They handle arrays of ints, shorts, longs, chars, bytes,
floats, doubles, and Strings, and Vectors of objects. They will
also sort the keys of a hashtable - a useful way to sort a set
of objects based on the value of one field in the object. These
libraries are available free for non-commercial use, and for
a fee to commercial users. They are compatible with JDK version
1.1 and above. These libraries can be installed on any platform
that has a JDK 1.1 (or above) port and an unzip utility, but
instructions are only given for the two most common - Windows
and Unix.
Windows
Installation
This library is provided in zip format, which can be unzipped
on any common platform (and some uncommon ones). If you don't
have an unzip utility, you can get one free from the Info-Zip
Home Page. Once you have downloaded the library, choose a location
for it (the example is c:\silentq). Move the zip file to that
location, and unzip it:
move sort.zip c:\silentq
cd c:\silentq
unzip sort.zip
This will create a directory called com, along with assorted
documentation. Add this directory to your classpath:
set classpath=%classpath%;c:\silentq
The library is now installed, and can be incorporated into
your code.
Unix Installation
This library is provided in zip format, which can be unzipped
on any common platform (and some uncommon ones). If you don't
have an unzip utility, you can get one free from the Info-Zip
Home Page. Once you have downloaded the library, choose a location
for it (the example is /usr/local/silentq). Move the zip file
to that location, and unzip it.
mv sort.zip /usr/local/silentq
cd /usr/local/silentq
unzip sort.zip
This will create a directory called com, along with assorted
documentation. Add this directory to your classpath:
CLASSPATH=$CLASSPATH:/usr/local/silentq;
export CLASSPATH
or
setenv CLASSPATH $CLASSPATH:/usr/local/silentq
The library is now installed, and can be incorporated into
your code.
Using Sort Classes
The sorting methods in the library are all static methods,
so they can be used without instantiating any classes. In addition,
all methods (except the Hashtable methods) both sort the data
in place and return the sorted data, so you can choose the syntax
that works best for your application. For example, to QuickSort
an array or Vector called data:
QuickSort.sort(data);
or
data = QuickSort.sort(data);
The Hashtable sort allows you to sort a set of objects based
on one of the fields in the object. For example:
class Data {
String name;
Date entered;
}
Data data1 = new Data();
data1.name = "Jeremy";
data1.entered = new Date();
Data data2 = new Data();
data2.name = "Miriam";
data2.entered = new Date();
Hashtable hash = new Hashtable();
hash.put(data1.name, data1);
hash.put(data2.name, data2);
Vector results = QuickSort.sort(hash);
You can then use the results vector (a sorted list of keys)
to retrieve the elements from the Hashtable.
Support
Please send any questions, comments, or bugs to support@silentq.com.
Priority will go to those with support contracts, but all mail
will be read, and all bugs will be recorded.
Copyright 1999, SilentQ
Software Company