Find the kth to last element of a singly linked list
Problem description :
Implement a non-recursive algorithm to find the kth to last element of a singly linked list.
Input : A linked list
Output : A value of a node in a linked list
- Iterate through the list with two pointers
ksteps ahead of
p2is at the end of linked list
p1is at the
kthto last element of a singly linked list.