Corrections for the First Edition

Data Structures and Other Objects Using Java (First Edition)
by Michael Main ISBN 0-201-35744-5, Softcover, 800 pages, 1999

Here is a list of corrections for the first edition of the text. I don't yet have any corrections for the second edition, so please send any errors that you spot--thanks!
--Michael Main (

Page 17: The if-else statement to round a number was written for an earlier
version of Java. A corrected version is available at

Page 66: The first two assignments in the distance method should be:
   a = p1.x - p2.x;
   b = p1.y - p2.y;

Page 81: Last line should be: These two locations have different coordinates.

Page 87: Last line of Exercise 6 should activate exercise.getFlow().

Pages 98 and 99: Last assignment in the code should be: scores[3] = 56;

Pages 124 and 217: There is an extra left brace on 2nd line of clone method.

Page 138: The documentation is wrong for the first constructor (which has
no parameter).

Page 139 and 231: The postcondition for addAfter should read: If there was a 
current element, then addAfter places the new element AFTER the current element

Pages 141 and 233: The removeCurrent methods of the Sequence classes should
be void (rather than boolean). Also, the array version (page 138) should
have an ensureCapacity method, similar to the bag on page 109.

Page 154: On third bullet: TextField should be TextArea (twice).

Page 167: Last assignment in ex 15 should be: data[currentIndex] = element;

Page 173, Last two lines of Figure 4.2 should declare variables of type
IntNode (not Node).

Page 195: In Figure 4.8, the loop should initialize i = 1.

Page 201: copyInformation should be copyInfo to match the subsequent text.

Page 230: The first two cases should use listCopyWithTail rather than
listCopy (to make it easy to set the tail of the clone).

Page 265: The first line of the body of the while loop should be:
cursor =;

Page 281: Last paragraph should say that "the POP method indicates a stack
UNDERFLOW by throwing an EmptyStackException."

Page 288: The bottom of the tip should say "an ordinary right 
parenthesis ')' (the book has the wrong direction of parenthesis).

Page 320: Exercise 15 should refer to Figure 6.8 on page 312.

Page 361: The insert implementation here is wrong; the right implementation
is back on page 358.

Page 379: At the top of the page, the activation record is the THIRD call
to superWriteVertical (not the second).

Page 458: The last comment in print should read: Print the right subtree
(or a dash if there is a left child and no right child)

Page 461: The return type of the string compareTo function is int.

Page 474: The data type of addroot should be IntBTNode and the
  activation of treeCopy should be IntBTNode::treeCopy.

Page 477: The last line of the solution to number 7 should be
private TreeNode[] links, and the constructor has: links = new TreeNode[4].

Page 478: The last two lines (in the else clause) should be:
  current.setLeft(new BTNode(guessAnimal, null, null));
  current.setRight(new BTNode(correctAnimal, null, null));

Page 546: The if-statement in the remove function must also have manyItems--;

Page 549: The boolean expression in nextIndex should be: (i+1 == data.length)

Page 553: In general, the return value from hash2 could be as large as
data.length-1, but Knuth's particular hash2 will never exceed data.length-2.

Pages 670-671: The two Melbourne-Hobart edges should be in opposite directions.

Page 726: The private function readChar returns ZERO_CHAR (not -1) for EOF.

Page 730: The if-else statement to round a number was written for an earlier
version of Java. A corrected version is available at:

Page 745: The data type of initialData should be Object (rather than int).

Page 747: The first statement of the while loop should be:
          cursor =;

Page 748: The data type of target should be Object (rather than int).