I'm curious if you can explain why, in the listed answer for
insertAfter on Page 39, you decide to traverse the list, using
curPos, rather than just trust that the
elem provided is actually in the list, and merely insert a new
Element with the value
data after it?
By traversing, you produce O(n) code. If you trust that
elem is in the list, you produce O(1) code. I'm as paranoid as the next coder, but it seems a bit, er - cynical - to not trust that
elem is in the list referenced by
head and
tail.
I realize that this is just a difference in how exhaustively the coder does error checking; but considering the emphasis in the book on efficiency, it seems an odd choice.
Regards,
-Matt