struct ListNode* oddEvenList(struct ListNode* head ) { // write code here if(head == NULL) return NULL; struct ListNode *odd, *oddHead, *even, *evenHead; odd = oddHead = even = evenHead = NULL; struct ListNode *cur = head; int n=1; while(cur) { if(n % 2 != 0) { if(odd == NULL) odd = oddHead = cur; else{ odd->next = cur; odd = cur; } } else{ if(even == NULL) even = evenHead = cur; else{ even->next = cur; even = cur; } } cur = cur->next; n++; } if(even) even->next = NULL; odd->next = evenHead; return oddHead; }