What's wrong in this 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;
Node *n=new Node(data);
temp->next=n;
n->next==NULL;
return;

}
void insertlist(Node * &head,int n)
{
int num;

while(n--)
{
	cin>>num;
	insertattail(head,num);

}

}
int main()
{
Node *head=NULL;
int n;
cin>>n;
insertlist(head,n);
Node *temp=head;
while(temp!=NULL)
{
temp=temp->next;
Node *temp1=temp;
while(temp1!=NULL)
{

		if((temp1->data %2)==1)
		{
			int tem=temp1->data;
			temp1->data=temp->data;
			temp->data=tem;
			break;
		}
		temp1=temp1->next;
	}
}
while(head!=NULL)
{
	cout<<head->data<<" ";
	head=head->next;
}

}

@Mihir163 hey your logic is not correct,maintain two separate head and tail one for even and one for tail now if current node is even attach that node to even ll and if odd attach to odd ll.Now connect both ll according to condition given in qstn.