--- Vic Wagner <[EMAIL PROTECTED]> wrote:
> Mickey Mathieson wrote:
> > --- Vic Wagner <[EMAIL PROTECTED]> wrote:
> >
> >
> >> Mickey Mathieson wrote:
> >>
> >>> --- Vic Wagner <[EMAIL PROTECTED]> wrote:
> >>>
> >>>
> >>>
> >>>> Mickey Mathieson wrote:
> >>>>
> >>>>
> >>>>> --- sunil_h_v <[EMAIL PROTECTED]> wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>> Hi everyone,
> >>>>>>
> >>>>>> I have a problem, i need the logic for it, i
> >>>>>>
> >>>>>>
> >>> don't
> >>>
> >>>
> >>>>>> want any code
> >>>>>> snippets or program for it. If you know please
> >>>>>> explain the logic for this.
> >>>>>>
> >>>>>> Given a linked list of n nodes, n is an odd
> >>>>>>
> >>>>>>
> >>>> number,
> >>>>
> >>>>
> >>>>>> i.e; there are odd
> >>>>>> number of nodes in it, I need to find the
> >>>>>>
> >> middle
> >>
> >>>>>> node of the linked
> >>>>>> list, i am supposed to traverse only once, i am
> >>>>>>
> >>>>>>
> >>>> not
> >>>>
> >>>>
> >>>>>> supposed to use
> >>>>>> any kind of an array to store the address
> >>>>>>
> >> values
> >>
> >>>>>>
> >>>>>>
> >>>> of
> >>>>
> >>>>
> >>>>>> the nodes, i am
> >>>>>> allowed to use pointers.
> >>>>>>
> >>>>>> How do i go about solving this problem ?
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>> 1). Calculate the middle node by using simple
> >>>>> arithmetic.
> >>>>>
> >>>>>
> >>>>>
> >>>> If you don't know the length of the list
> >>>>
> >> beforehand,
> >>
> >>>> what "simple
> >>>> arithmetic" do you perform?
> >>>>
> >>>>
> >>> Where does it state that you don't know the length
> >>>
> >> of
> >>
> >>> the list?
> >>>
> >>>
> >>>
> >
> >
> >> it doesn't say you DO know, therefore you don't.
> >>
> >
> >
> > depends on how you look at things - half empty or half
> > full.
> >
> >
> empty/full has nothing to do with it.
>
> correct / incorrect
>
> correct trumps
IIRC, there is a trick using two pointers to run through the list. One
of the pointers goes ahead one node at a time, the other proceeds two
at a time. When the second reaches the end (next==NULL), the first has
reached middle. A simple counter maintained throughout can give the
length.
Regards,
Mohan S N
____________________________________________________________________________________
Check out the hottest 2008 models today at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html