What is wrong in the function with reference to even-after-odd problem

void prob(node *&head)
{
node *current = head;
node *prev = head;
node *n = head;
while (current->next != NULL)
{
if (current->next->data % 2 != 0)
{
prev = current;
current = current->next;
n = current->next;
prev->next = n;
current->next = head;
head = current;
current = prev;
}
else
current = current->next;
}
}

Sir this function is doing what is stated in the problem then why some test cases are coming wrong.

hello @apoorv_tg

relative order between odds , and between even must remain same

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.