データ構造実験値チェーンテーブル5:単一チェーンテーブルの分割
3663 ワード
N , , , 。 。
N;;
N 。
;
;
。
10 1 3 22 8 15 999 9 44 6 1001
サンプル4 6 22 8 44 6 1 3 15 999 9 1001
#include
#include struct node { int data; struct node *next; }; int main() { int n; struct node * head1, *head, *p, *q,*tail,*tail1; scanf("%d",&n); head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; tail=head; for(int i=0;i next=NULL; scanf("%d",&p->data); tail->next=p; tail=p; } p=head->next; int a=0, b=0; head1=(struct node *)malloc(sizeof(struct node)); head1->next=NULL; tail1=head1; tail=head; q=p->next; while(p!=NULL) { if(p->data%2==0) { p->next=NULL; tail->next=p; tail=p; a++; } else { p->next=NULL; tail1->next=p; tail1=p; b++; } p=q; if(q!=NULL) q=q->next; } printf("%d %d
",a,b); p=head->next; while(p!=NULL) { if(p->next==NULL) printf("%d
",p->data); else printf("%d ",p->data); p=p->next; } q=head1->next; while(q!=NULL) { if(q->next==NULL) printf("%d
",q->data); else printf("%d ",q->data); q=q->next; } return 0; }