Giving wrong answer for test case 0

#include
using namespace std;

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

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

};

void input(node*&head , int key){
if(head == NULL){
head = new node(key);
}
else{
node * emp = head;
while(emp -> next != NULL){
emp = emp ->next;
}
node * temp = new node(key);
emp->next = temp;
}
}

void print (node * head){
while(head!=NULL){
cout<<head ->data<<" ";
head = head->next;
}
}

node* next_odd(node *current){
while(current!=NULL){
if((current->data %2) != 0){
return current;
}
current = current->next;
}
return current;
}

void even_after_odd(nodehead){
node
first = head;
node* second = head;
while(second!=NULL){
if((first->data%2) == 0 ){
second = next_odd(second);
}
if(second!= NULL)
{swap(first->data,second->data);
second = second->next;}
first = first->next;

}
return;

}

int main() {
node* head = NULL;
int len;
cin>>len;
for(int i=0;i<len;i++){
int key;
cin>>key;
input(head,key);

}
even_after_odd(head);
print(head);
return 0;

}

hello @saurabh66
pls share ur code using cb ide

@saurabh66
image
u r not maintainig relative order

give me some hint on how to maintain the relative order i am completely blank

put all even numbers in a list and all odd numbers in seprate list and then add head of even list to the tail of odd list and return head of odd 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.