Daily One Algorithm
A blog dedicated to those who live, drink and eat Algorithms.
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:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment