class Solution {

public:

ListNode* oddEvenList(ListNode* head) {

```
if(!head || !head->next)
return head;
int count = 1;
ListNode *oddHead = head,*oddTail = head;
ListNode *evenHead = head->next,*evenTail = head->next;
ListNode *temp = evenHead->next;
oddHead->next = NULL;
evenHead->next = NULL;
while(temp != NULL)
{
if(count%2 == 1)
{
oddTail->next = temp;
oddTail = temp;
temp = temp->next;
oddTail->next = NULL;
}
else
{
evenTail->next = temp;
evenTail = temp;
temp = temp->next;
evenTail->next = NULL;
}
count++;
}
oddTail->next = evenHead;
return oddHead;
}
```

};