Mohan S N wrote: > 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
Technically, that will result in 1.5 scans of the linked list. Peter had the correct idea - assuming the linked list could be traversed in both directions - start from both ends and, when you meet in the middle, that is the middle node. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
