finding middle node in liked list

Discussion in 'C' started by dhanulakshmi, Nov 29, 2006.

  1. dhanulakshmi

    dhanulakshmi New Member

    Joined:
    Nov 29, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    how to find the middle node of the linked list having some 10 nodes....i dont want to count the nodes n find the middle one....i have to travel the entire list for only one time....after coming to the end of the node ,i have to recpgnise n print the middle node

    thanks n regards
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The best possible way out is do have a pointer to the middle node at the time of inserting as you can never know which one is the middle node unless you travel the whole list.

    You can also try one more thing is while travelling to find the middle node store the middle node to the particular node and when you will reach the end of the list you have the middle node stored.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice