Re: The minimum value of a binary tree question




"Paul N" <gw7rib@xxxxxxx> wrote in message
news:9ffda5b8-c5f6-4164-bb56-fdc6791fadfe@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 18 Jan, 18:17, Chad <cdal...@xxxxxxxxx> wrote:
Oh yeah. I forgot that current->data is outside the loop. And this
reminds me that a while back I had asked a similar question on
comp.lang.c. I'm suspecting that there is some underlying programming
concept that I haven't quite grasped yet.

Perhaps you mean the concept of "look before you leap"?

For instance, if you want to find the end of a linked list, then this
code:

while (thing) { thing = thing -> next; }

will not work because you run off the end of the list before you stop.
And once thing is NULL, you can't do "thing = thing -> prior" to get
back into the list again.

for some uses, it may be useful to instead keep a 'prev' pointer:
prev = NULL;
while (thing) { prev = thing; thing = thing -> next; }

granted, this would likely be pointless in this case, but this is also
useful for some cases...



.



Relevant Pages

  • Re: The minimum value of a binary tree question
    ... reminds me that a while back I had asked a similar question on ... I'm suspecting that there is some underlying programming ... but wouldn't 'thing' in the while loop *get*/ ...
    (comp.programming)
  • Re: The minimum value of a binary tree question
    ... reminds me that a while back I had asked a similar question on ... I'm suspecting that there is some underlying programming ... Perhaps you mean the concept of "look before you leap"? ...
    (comp.programming)
  • Re: Steam Locomotive Crash
    ... > President, The Sparta Railroad ... Reminds me of "There are things we know we don't know"... ... David. ... Prev by Date: ...
    (rec.models.railroad)
  • Re: I am in bad mood
    ... > Which reminds me. ... Classic English. ... Best Regards, ... Prev by Date: ...
    (comp.sys.sinclair)
  • Re: I am in bad mood
    ... Geoff Wearmouth wrote: ... > Which reminds me. ... Kind Regards, ... Prev by Date: ...
    (comp.sys.sinclair)