问题描述

解决方案
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if(!head||!head->next) return head;
ListNode* oddlist=head;
ListNode* evenlist=head->next;
ListNode* node=head->next;
while(evenlist)
{
oddlist->next=evenlist->next;
if(oddlist->next!=NULL)
{
oddlist=oddlist->next;
evenlist->next=oddlist->next;
}
evenlist=evenlist->next;
}
oddlist->next=node;
return head;
}
};