/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: void reorderList(ListNode* head) { ListNode* midnode = split(head); ListNode* pre = NULL; while(midnode) { ListNode* temp = midnode -> next; midnode -> next = pre; pre = midnode; midnode = temp; } ListNode* head1 = head,*head2 = pre; while(head1 != head2){ ListNode* n1 = head1 -> next; ListNode* n2 = head2 -> next; head1 -> next = head2; if(n1 == head2) break; head2 -> next = n1; head1 = n1; head2 = n2; } } ListNode* split(ListNode* head) { ListNode* slow = head,* fast = head; while(fast != NULL && fast -> next != NULL){ slow = slow -> next; fast = fast -> next -> next; } return slow; } }; 标签:head,ListNode,head2,fast,next,链表,重新,排序,midnode From: https://www.cnblogs.com/hbro/p/17406962.html