Hey Mr.Debasish,
Thanks for the reply, but your logic can't be applied to my problem,
because i do not know of the last node, and it is a singly linked
list, so i can't traverse backwards in that.
I got my logic long back and i even posted the code for that, it works
fine, i used two integer variables and a pointer for that
while(ptr->link != NULL ) {
if ( mid != n/2 ) {
mid ++;
p=p-link;
}
n++;
ptr=ptr->link;
}
p is my temporary pointer, ptr is the starting node passed to the
function, when mid = n/2 and n is the max the p will be pointing at
the middle node.
Thanks a lot for the reply,
Regards,
Sunil.
--- In [email protected], debasish deka <[EMAIL PROTECTED]> wrote:
>
> Otherwise you can take two pointers............
> One at the beginning other at the end....
> Increment the one pointing at the beginning ...and decrement one
pointing to the end......
> When both of their self referential pointer point to the same
node...its the middle element......the one you wanted....
>
> Now the question arise whether you know are allowed to have the last
node or not....
> Do care to reply....
> Debasish
>
> Mickey Mathieson <[EMAIL PROTECTED]> wrote:
> --- sunil_h_v <[EMAIL PROTECTED]> wrote:
>
> > Hi everyone,
> >
> > I have a problem, i need the logic for it, i dont
> > 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.
>
> 2). Traverse the list until reaching the calculated
> middle node.
>
> 3). Return the node information.
>
> Mickey M.
> Construction Partner Inc.
> http://www.constructionpartner.com
>
> __________________________________________________________
> Pinpoint customers who are looking for what you sell.
> http://searchmarketing.yahoo.com/
>
>
>
>
>
> Karmennevaya Dhikaraste, Maaphaaleshu Kadaachanah
>
> ---------------------------------
> Now you can chat without downloading messenger. Click here to know how.
>
> [Non-text portions of this message have been removed]
>