标签:des style io ar color 使用 sp for 数据
6 5 1 23 26 45 66 99 14 21 28 50 100
1 14 21 23 26 28 45 50 66 99 100
示例程序
#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; tail=head; for(i=1;i<=n;i++) { p=(struct node *)malloc(sizeof(struct node)); scanf("%d",&p->data); p->next=NULL; tail->next=p; tail=p; } return head; } struct node * Merge(struct node *head1, struct node *head2) { struct node *p1, *p2, *tail; p1=head1->next; p2=head2->next; tail=head1; free(head2); while(p1&&p2) { if(p1->data < p2->data) { tail->next=p1; tail=p1; p1=p1->next; } else { tail->next=p2; tail=p2; p2=p2->next; } } if(p1) tail->next=p1; else tail->next=p2; return(head1); } int main() { struct node * head1, *head2, *p; int n, m; scanf("%d %d",&n,&m); head1=Creat(n); head2=Creat(m); p=Merge(head1,head2); while(p->next->next!=NULL) { printf("%d ",p->next->data); p=p->next; } printf("%d\n",p->next->data); return 0; }
标签:des style io ar color 使用 sp for 数据
原文地址:http://blog.csdn.net/u013634961/article/details/41858745