Node* FindMiddleNode(Node *head)//快慢指针法
{
Node *fast=head,*slow=head;
if(fast==slow==NULL)
return NULL;
else if(fast->next==NULL)
return fast;//说明只有一个节点
while(fast != NULL)
{
fast = fast->next->next;
slow = slow->next;
if(fast==NULL ||fast->next==NULL)//适用于奇数或偶数个结点
{
return slow;
}
}
}