here goes a soln for not just 15th elem frm da end of da linked list rather any nth elem u wanna find out...
:)
take 2 ptrs:ptr1 and ptr2.
ptr1=ptr2=head of the linked list
move ptr1 by n steps frm da head of linked list.
loop until ptr1!=NULL :
do
{ ptr2=ptr2->next
ptr1=ptr1->next
}
done
ptr2 wud b pointing at the nth element frm the end of the linked list...
Hope u got the soln....
Find the 15th element from the end of linked list
you might want to handle the error condition when the entire list is smaller than 15 or the given 'n'
Find the 15th element from the end of linked list
here goes a soln for not just 15th elem frm da end of da linked list rather any nth elem u wanna find out...
:)
take 2 ptrs:ptr1 and ptr2.
ptr1=ptr2=head of the linked list
move ptr1 by n steps frm da head of linked list.
loop until ptr1!=NULL :
do
{ ptr2=ptr2->next
ptr1=ptr1->next
}
done
ptr2 wud b pointing at the nth element frm the end of the linked list...
Hope u got the soln....
:)