finding middle node in liked list

dhanulakshmi's Avatar
Light Poster
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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.