Re: Middle of a singly linked list of unknown length




"Kenneth Brody" <kenbrody@xxxxxxxxxxx> wrote in message
news:484954EE.DE3F5A81@xxxxxxxxxxxxxx
Himanshu Chauhan wrote:

Hi!

I was wondering, In the first parse of a singly linked list of unknown
length, is it possible to know when we are at middle of the linked list?

The me rephrase the problem, and see if you can find a solution:

Drive down this road and stop halfway to a destination which I
have not yet revealed.

That's not quite the same. In that case you would not know when you got to
the destination so it's unsolveable. A linked list however has a definite
end point, assuming it's not circular.

Better, 'stop halfway to the end of the road of unknown length'. Easily done
by traversing the entire length one and a half times.
--
Bartc


.



Relevant Pages