我是这样写的,最后输出不出来东西,求大佬帮忙
#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;
}