[LCP]linked list question

Mike & Penny Novack stepbystepfarm at shaysnet.com
Wed Apr 3 00:02:05 UTC 2002


> Anyway I managed to solve the problem after making myself some
drawings
> and going over it with a big cup'o'coffee.
> Thanks to anybody who would have helped.

Joachim,
    THAT is precisely the best way to proceed when code doesn't work as
you expected. In other words, to analyze what you expect it to do in
abstract terms (eg: your drawings) rather than staring at the code. But
there is another issue here related to your original question.

> I have a problem with recursively reversing the items in a linked
list.

    WHAT precisely do you intend. There are MULTIPLE (very different)
problems which can properly described as "reversing a list". Especially
when you use the word "recursively".

a) Did you mean the "recursively" to refer to WHAT you intend to do or
HOW you intend to do it? In the former case you mean something like
"reverse a list and all its sublists" so a list (A (B C D) (E F))
becomes ( (F E) (D C B) A) but if only reversal at the top level was
meant becomes ((E F) (B C D) A).

b) Did you mean do as a "function" (ie: return a new list with the
original list left unchanged) or was this to be a "reversal in place"?
In the former case your "process" will involve allocating either as many
new nodes as the original list contained or as many as exist at the top
level (refer back to "a").

    What I am really trying to say by this is that the FIRST thing you
should always do is be absolutely clear about what your program is
SUPPOSED to do because there is no way you can get the code right until
you have accomplished that. In other words, you might be able to code it
and test your code and everything looks all right but since it isn't
actually doing what was intended the whole larger program (of which this
is a component) may fail to work.

Mike





More information about the linuxCprogramming mailing list