Introduction
Algs4Net is a .NET library port of algs4.jar
with the goal to serve instructors and programmers who adopts the
Algorithms, 4th Edition textbook and would
prefer to follow and demonstrate the text’s algorithms using C# in a .NET
environment. To meet the goal, Algs4Net was built using the following conventions:
-
Most classes in Algs4Net were ported from the corresponding classes in algs4.jar
with the class names, identifiers, and algorithm flows being kept intact whenever possible
-
Each class in Algs4Net has a public static method
void MainTest(string[] args)
as a substitute for the static main method in Java. As C# does not allow multiple
Main(string[] args)
entries in a project, a command-line tool, algscmd, was
developed to call these MainTest methods.
-
A part from keeping the class names and algorithm flows, certain method names in
algs4.jar classes were slightly changed to follow a C# coding convention as follow:
- First letters of public methods are in upper case (upper camel casing).
-
C# properties are used in place of simple accessor methods. Most notably,
Java’s size() and isEmpty() methods become Count and IsEmpty properties respectively.
-
C# indexers are used when the context permits. Particularly, the Algs4Net
symbol table classes such as BST are augmented with key-value indexers.
-
Since not all C# types are reference types, boxing/unboxing are used to
convert value types to reference types. Whenever the conversion is not possible,
the C# compiler will detect the condition or a NullReferenceException is thrown
at runtime.
-
When an exception needs to be thrown, the exception is selected following
the official .NET Framework libraries implementation. For example, accessing an
empty LinkedQueue object is a condition for InvalidOperationException, in the same
manner as the System.Collections.Generic.Queue object would do.
-
Finally, classes in Algs4Net were provided with well-formed XML comments to generate
HTML help documentation.
Notes: As of now, most of the classes that cover the six chapters of the
algs4.jar library
were ported, with the exception of the CollisionSystem class, classes in
the Beyond section starting from the FenwickTree class and all classes
in the Exercise solutions section.
To use the library, clone or download the
Algs4Net
solution and see Quick Start for how to use the library.
Refer the API Reference for an online documentation
of the library's classes.