/**
* 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 == NULL) {
return head;
}
ListNode *oddNode = head;
ListNode *evenNode = head->next;
ListNode *evenhead = head->next;
while (evenNode && evenNode->next) {
oddNode->next = evenNode->next;
evenNode->next = evenNode->next->next;
oddNode = oddNode->next;
evenNode = evenNode->next;
}
oddNode->next = evenhead;
return head;
}
};