代码拉取完成,页面将自动刷新
struct ListNode* midList(struct ListNode* head)
{
struct ListNode* slow = head;
struct ListNode* fast = head;
while (fast->next != NULL && fast->next->next != NULL) {
slow = slow->next;
fast = fast->next->next;
}
return slow;
}
void mergeList(struct ListNode* l1,struct ListNode* l2)
{
struct ListNode* temp1;
struct ListNode* temp2;
while (l2 != NULL) {
temp1 = l1->next;
temp2 = l2->next;
l1->next = l2;
l1 = temp1;
l2->next = l1;
l2 = temp2;
}
}
struct ListNode* reserveList(struct ListNode* head)
{
struct ListNode* pre = NULL;
struct ListNode* cur = head;
while (cur != NULL) {
struct ListNode* nextTemp = cur->next;
cur->next = pre;
pre = cur;
cur = nextTemp;
}
return pre;
}
void reorderList(struct ListNode* head){
struct ListNode* mid = midList(head);
struct ListNode* L1 = head;
struct ListNode* L2 = mid->next;
mid->next = NULL;
L2 = reserveList(L2);
mergeList(L1,L2);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。