class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if(head==NULL || head->next==NULL){
return head;
}
ListNode* odd=head;
ListNode* even=head->next;
ListNode* evenHead=head->next;
while(odd->next!=NULL && odd->next->next!=NULL){
odd->next=odd->next->next;
odd=odd->next;
}
while(even!=NULL && even->next!=NULL){
even->next=even->next->next;
even=even->next;
}
odd->next=evenHead;
return head;
}
};
Error: AddressSanitizer: heap-use-after-free on address
{1,2,3,4,5,6,7,8}================>{1,3,3,5,7,2,4,6}