1 typedef struct Node { 2 int data; 3 Node* next; 4 }Node; 5 6 Node* find_mid_node(Node* head) { 7 //检查传入参数,防止空节点 8 if (head) 9 return head; 10 11 //一步指针与两步指针 12 Node* one_step = two_step = head; 13 14 //当两步指针为NULL或者尾节点,一步指针就是中间节点 15 while(two_step && two_step->next) { 16 two_step = two_step->next->next; 17 one_step = one_step->next; 18 } 19 20 return one_step; 21 } 22