Wednesday, July 12, 2006

Nth Element from end SLL

/*
How to find nth element from end of a single linked list.
*/
list_ptr *p1, *p2;

p1 = p2 = list.head

for( i = 0; i < n; ++i )
p2 = p2->next;

while( p2 )
{
p1 = p1->next;
p2 = p2->next;
}

No comments: