List five of data structure experiment: singly linked lists of split
Time Limit: 1000 ms Memory Limit: 65536 KB
Submit Statistic
Problem Description
Input N integer order to establish a singly linked list, the singly linked lists split into two child list, the first child list for all of the even number, the second is the list for all the odd number, two child relative order of data in the table are consistent with the original list,
Input
The first line of input integer N;;
In the second line of the input N integers,
The Output
The first line output, respectively, even the number of elements in the list with an odd number of chain table;
The second line in the output even list all of the data;
The third line output in turn odd child list all of the data,
Example Input
10
1 3 22 August 15 999 9 44 6 1001
Example Output
4 6
22 8 44 6
1 3 15 999 9 1001
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
Struct node
{
int data;
Struct node * next;
};
Int main ()
{
Int n, a=0, b=0;
Head1 struct node * head, * and * head2, * p * q * t1, t2 *;
The scanf (" % d ", & amp; N);
The head=(struct node *) malloc (sizeof (struct node));
Head1=(struct node *) malloc (sizeof (struct node));
Head2=(struct node *) malloc (sizeof (struct node));
The head - & gt; Next=NULL;
Head2 - & gt; Next=NULL;
Head1 - & gt; Next=NULL;
Q=head;
While (n -)
{
P=(struct node *) malloc (sizeof (struct node));
The scanf (" % d ", & amp; P - & gt; data);
Q - & gt; Next=p;
Q=p;
}
P=the head - & gt; next;
Q=p - & gt; next;
The head - & gt; Next=NULL;
T1=head1; T2=head2;
While (p!=NULL)
{
If (p - & gt; Data % 2==0)
{
T1 - & gt; Next=p;
T1=p;
a++;
}
The else
{
T2 - & gt; Next=p;
T2=p;
B++;
}
P=q;
If (q!=NULL)
Q=q - & gt; next;
}
P=head1 - & gt; next;
Q=head2 - & gt; next;
Printf (" % d % d \ n ", a, b);
While (p!=NULL)
{
Printf (" % d ", p - & gt; data);
If (p - & gt; Next!=NULL)
Printf (" ");
The else
printf("\n");
P=p - & gt; next;
}
While (q!=NULL)
{
Printf (" % d ", q - & gt; data);
If (q - & gt; Next!=NULL)
Printf (" ");
The else
printf("\n");
Q=q - & gt; next;
}
return 0;
}