标签:des style blog io ar color 使用 sp for
10 1 3 22 8 15 999 9 44 6 1001
4 6 22 8 44 6 1 3 15 999 9 1001
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; struct node *Creat(int n) { struct node *head, *tail, *p; int i; head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; for(i=1;i<=n;i++) { p=(struct node *)malloc(sizeof(struct node)); scanf("%d",&p->data); p->next=head->next; head->next=p; } return head; } struct node * Split(struct node * head1) { struct node *head2, *p, *q; int a=0, b=0; head2=(struct node *)malloc(sizeof(struct node)); head2->next=NULL; p=head1->next; head1->next=NULL; q=p->next; while(p!=NULL) { if(p->data%2==0) { p->next=head1->next; head1->next=p; a++; } else { p->next=head2->next; head2->next=p; b++; } p=q; if(q!=NULL) q=q->next; } printf("%d %d\n",a,b); return head2; }; int main() { int n; struct node * head1, *head, *p, *q; scanf("%d",&n); head=Creat(n); head1=Split(head); p=head->next; while(p!=NULL) { if(p->next!=NULL) printf("%d ",p->data); else printf("%d\n",p->data); p=p->next; } q=head1->next; while(q!=NULL) { if(q->next!=NULL) printf("%d ",q->data); else printf("%d\n",q->data); q=q->next; } return 0; }
标签:des style blog io ar color 使用 sp for
原文地址:http://blog.csdn.net/u013634961/article/details/41858669