/**
* 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 == nullptr)
return nullptr;
if(head!=nullptr && head->next == nullptr)
return head;
if(head!= nullptr && head->next!= nullptr && head->next->next ==nullptr)
return head;
ListNode* s = head;
ListNode* help = head->next;
ListNode* f = head->next;
while(f->next != nullptr){
s->next = f->next;
s = s->next;
if(s->next != nullptr){
f->next = s->next;
f = f->next;
}else{
f->next = nullptr;
break;
}
}
cout << s->val;
s->next = help;
return head;
}
};