Re: Singly Linked LIst and Objects Newbie Question



Philipp Leitner wrote:
I might be missing something totally obvious here, but where in your
code are you setting the 'head' of the list? This is something that
should probably go into the block where you check for the 'first
value'.

Another sidenote: you should stick to the standard conventions of CS,
like that the first element of a list has the index '0', not '1' as in
your case (see for instance arrays, the java.util collections, ...)

What do you mean by "CS"?

Java arrays and implementations of java.util.List are zero-based in fact, not by convention. java.sql.PreparedStatement and ResultSet count parameters columns respectively from one, not zero. I'm not sure one can assert the existence of a convention.

It is enough, though, that the fact of arrays and java.util.Lists is that they index from zero. The advice to do likewise in classes that extend or wrap arrays or java.util.List is sound. Among other things, it eliminates the confusing and error-prone offsets by one that abound in the OP's code.

To the OP: your main() method ought to do something to display or otherwise prove that the contents of your list are what you expect them to be.

--
Lew
.



Relevant Pages

  • Re: Double arrays in ext. code garbage when viewed in labview.
    ... NumericArrayResize to allow for my code to allocate memory in arrays ... the only problem comes because labview is not looking at the bytes ... seems to always show up as zero in labview, regardless of what I set it ... the double so as to see this, but still this first element is always ...
    (comp.lang.labview)
  • java.util.prefs.Preferences and arrays
    ... multiple copies of each field (i.e. arrays). ... Is there a standard ... convention to fudge it? ...
    (comp.lang.java.programmer)
  • Re: How to compile Mopac 7.1 using g77 or gfortran
    ... used the old "convention" of specifying argument arrays of unknown length in ... you'd expect from the old f66 convention of using 1 for the upper bound ...
    (comp.lang.fortran)
  • Re: Unsigned Indexing (was: some other sad story)
    ... >) convention of zero-based arrays, no matter whether they would track ... >) beauty queens or the temperature in Minsk, or Chicago. ... > arrays in C, and you don't need to do a lot of rewriting for it either. ...
    (comp.programming)
  • Re: C exe on winXP memory limitation
    ... precission integers are stores in arrays. ... the windows refuses to execute the program. ... Conventionally, #defines are given names in all capital letters, and variables are not given names with all capital letters. ... This is only a convention, but following it does make it easier for others to read your code. ...
    (comp.lang.c)