Idk why some cases are failed

#include

using namespace std;

class node

{
public:
int data;
node *next;
node(int d)
{
this->data = d;
this->next = NULL;
}
};

void insertattail (node *&tail, node *&head, int d)

{
if (tail == NULL)
{
tail = new node(d);
head = tail;
}
else
{
node *temp = new node(d);
tail->next = temp;
tail = temp;
}
}

void print(node *head)

{
while (head != NULL)
{
cout << head->data << " ";
head = head->next;
}
cout << endl;
}

void insertathead(node *&head, node *&tail, int d)

{
if (head == NULL)
{
head = new node(d);
tail = head;
return;
}
node *temp = new node(d);
temp->next = head;
head = temp;
}

int main()

{
int n;
cin >> n;
node *tail = NULL;
node *head = NULL;
while (n–)
{
int d;
cin >> d;
if (d % 2 != 0)
{
insertathead(head, tail, d);
}
else
insertattail(tail, head, d);
}

//even_odd(head, tail);
print(head);

return 0;

}

hi @rounaqkhandelwal24 u r not preserving the order
test case
5
1 2 1 2 3
ans should be 1 1 3 2 2

so do i have to consider the sorting as well?

@rounaqkhandelwal24 No the order in which they come

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.