对于网上的解法如下,
class OddEvenLink{
public:
LinkNode* oddEvenList(ListNode* head)
{
if(!head)
return head;
ListNode* first = head
ListNode* second = head->next;
ListNode* temp = second;
while(second && second->next)
{
first->next = second->next;
first = first->next;
second->next = first->next;
second = second->next;
}
first->next = temp;
return head;
}
}
本质上还是链表的自身插入,这里面是奇数位节点插入链表自身的某位置。