有如下链表节点定义:
Struct Node {
int value;
Node * next;
}
typedef struct Node { int value; Node * next; }Node; Node* getnode_rK(int k,Node* head) { cin>>k; if(k==0||head->next==NULL)//链表为空或k=0 return NULL; Node*Apoint=head->next; Node*Bpoint=head->next; while(k>1)//A指针先走K-1步 { Apoint=Apoint->next; k--; if(Apoint==NULL) return NULL; } while(Apoint->next!=NULL)//A B一起走,直到A到尾结点 { Apoint=Apoint->next; Bpoint=Bpoint->next; } return Bpoint; }