I'm getting into learning linked lists, and I have a fairly decent grasp on some of it. There is something I'm wondering though. Is there a way to index the nodes in a linked list without refering to it's distance from the root node?
For instance, the only way I know how to get to a specific node is to reset the pointer that goes through the list to point to the root node, then do Ptr = Ptr->next as many times as I need to get to the correct node.
Is there a better way of doing this?Code:int count = 0; transPtr = root; if ( transPtr != 0 ) { while ( transPtr->next != 0 && count != x) { transPtr = transPtr->next; count++; } }
Edit: Also, I hate trying to figure this stuff out from a small tutorial, does anyone know a good place to go to get linked lists in detail?