In a linked list find the nth node from the end of the list
list* foo(list* head, int n)
{
if(!head) return NULL;
list* p1=head;
list* p2=head;
int c=0;
while(p1->next)
{
p1=p1->next;
c++;
if(c>n)
return p2=p2->next;
}
if(c>n)
return p2;
else rturn NULL;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment