#include "myfuncs.h"
template <typename ListNode>
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead == NULL) return NULL;
Assert(k > 0, "k must larger than zero");
ListNode *pAhead = pListHead;
ListNode *pBehind = NULL;
for(unsigned int i=0; i<k-1; ++i) {
Assert(pAhead->m_pNext != NULL, "k is longer than the list's length");
pAhead = pAhead->m_pNext;
}
pBehind = pListHead;
while(pAhead->m_pNext != NULL) {
pAhead = pAhead->m_pNext;
pBehind = pBehind->m_pNext;
}
return pBehind;
}