Find the bug in the code

#include
using namespace std;

class node{
public:
int data;
node * next;

    node(int d){
        data = d;
        next = NULL;
    }

};

void insertAtTail(node * &head,int data){
if(head == NULL){
head = new node(data);
return;
}
node * temp = head;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = new node(data);
}

void print(node * head){
if(head == NULL){
return;
}
while(head){
cout<data<<" ";
head = head->next;
}
}
node * evenOdd(node * &head){
if(head == NULL || head->next == NULL){
return head;
}
node *t1=head;
node *t2=head;
while(t2){
if((t2->data)%2==0){
t2=t2->next;
}
else{
swap(t1->data,t2->data);
t1=t1->next;
t2=t2->next;
}
}
return head;
}
int main() {
node * head = NULL;
int l1;
cin>>l1;
int data;
for(int i=0;i<l1;i++){
cin>>data;
insertAtTail(head,data);
}
evenOdd(head);
print(head);
return 0;
}

Hey @ajaygangwar2030
The sequence of odd nodes and even nodes should be maintained in the solution, which is not followed in your code,
For example, take the test case:
7
1 2 4 3 8 5 6
The expected output is: 1 3 5 2 4 8 6
While the output of your code is:
1 3 5 2 8 4 6
So you might need to change your approach,
You may try taking two pointers to keep track of the list, maintain two separate lists for the odd and even nodes and merge them at the end to form a new list.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.