Java code for Lecture 1

  1. sumInt.java. The first pseudocode I showed: summing integers from 1 to a given n.
  2. theMatrix.java. I did not show this at all. It transposes a randomly generated square matrix.
  3. incompleteLoop.java. This is an implementation of the "incomplete loop" which I used as a means to teach you about worst-case and average case complexity. It generates a random input vector, runs the incomplete loop, and prints out the output.
  4. DLList.java. An implementation of a doubly-linked list. It is a SIMPLE implementation rather than a GOOD one. The choice of splitting it in two classes is very questionable from almost every point of view apart from a specific pedagogical one: it shows you can operate on a list from within each node as well as from a more global point of view. I would not advise you to re-use this list implementation in anything but the simplest codes: better stick to Java's LinkedList.

I am bound by my programming abilities to use the command line rather than most types of window-based environments, so no chance for Eclipse instructions - work them out for yourselves. However, if you fancy opening a terminal on a Linux machine, you can compile this code as follows. Given a java code file file.java, run:

javac file.java
java file.java [command line arguments]
It is necessary to check what command line arguments the programs take, since no check is made on these.