标签:
#ifndef COUNT_BACKWARD_H
#define COUNT_BACKWARD_H
#include<iostream>
struct ListNode
{
int m_value;
struct ListNode *m_pNext;
};
ListNode *findBackward_k(ListNode **head,int k_backward){
if(head==NULL||*head==NULL||k_backward==0){
return NULL ;
}
if((*head)->m_pNext==NULL&&k_backward==1){
return *head;
}
ListNode *m_phead=*head;
ListNode *pre_kbackward=m_phead;
ListNode *m_pend=m_phead-1;
int count_dis=k_backward;
while(m_pend->m_pNext!=NULL){
if(count_dis>0){
m_pend=m_pend->m_pNext;
count_dis--;
continue;
}
pre_kbackward=pre_kbackward->m_pNext;
m_pend=m_pend->m_pNext;
}
if(count_dis!=0){
throw("invalid input value");
}
return pre_kbackward;
}
#endif
标签:
原文地址:http://www.cnblogs.com/yml435/p/4655491.html