用C++实现将一串数字输入一个链表再将这个链表中的奇偶数分开存储在两个链表中,最后输出

我是这样写的,最后输出不出来东西,求大佬帮忙
#include
using namespace std;
struct node
{
int date;
node * next;
};
node * createList(int n);
void printList(node *a);
int main()
{
int n;
node * a = NULL;
node * A = NULL;
node * B = NULL;
node * m = NULL;
node * i = NULL;
cin>>n;
if(n > 0)
a = createList(n);
node *p;
p = a;
int x;
x = 1;
int y;
y = 1;
node *Atail = NULL;
node *Btail = NULL;
while(p->next != NULL)
{

    if(p->date%2 == 1 && x == 1)
    {   

        B = new node; 
        Btail = new node; 
        B->date = p->date;
        Btail = B;
        x = x+1;
    }
    else if (p->date%2 == 1 && x != 1)
    {
        node *temp = new node;


        temp->date = p->date;
        Btail->next = temp;
        Btail = temp;
    }

    else if(p->date%2 == 0 && y == 1)
    {   

        A = new node; 
        Atail = new node; 
        A->date = p->date;
        Atail = A;
        y = y+1;
    }
    else
    {
        node *temp = new node;
        temp->date = p->date;
        Atail->next = temp;
        Atail = temp;
    }
    p = p->next;
}
Atail->next = NULL;
Btail->next = NULL;
printList(A);
cout<<endl;
printList(B);
return 0;

}
void printList(node *a)
{
node * c = a;
while (c->next != NULL)
{
cout<< c->date<<' ';
c = c->next;
}
}
node * createList(int n)
{
node * temp = NULL, * tail = NULL, * head = NULL;
int num;
cin>>num;
head = new node;
if (head == NULL)
{
return NULL;
}
else
{
head->date = num;

    tail = head;
}
for (int i = 0; i<n-1;i++)
{
    cin>>num;
    temp = new node;
    temp->date = num;
    tail->next = temp;
    tail = temp;
}
tail->next = NULL;
return head;

}

c++,可以考虑使用stl

#include <iostream>
#include <list>
using namespace std;

void print(list<int> lit)
{
    list<int>::iterator iter = lit.begin();
    for(;iter != lit.end();iter++)
        std::cout << *iter << " ";
    std::cout << endl;
}

int main()
{
    int n;
    std::cin >> n;
    list<int> srcList,evenList,oddList;
    for(int i=0;i<n;i++)
    {
        int temp;
        std::cin >> temp;
        srcList.push_back(temp);
    }
    list<int>::iterator iter = srcList.begin();
    for(;iter != srcList.end();iter++)
        if(*iter % 2 == 0)
            evenList.push_back(*iter);
        else
            oddList.push_back(*iter);

    std::cout<<"even list:";
    print(evenList);
    std::cout<<"odd list:";
    print(oddList);

    return 0;
}