#include
#include
typedef
struct
node//定义结构体
{
int
score;
struct
node
*next;
}node;
node
*create(int
n)//创建链表
{
node
*head,*tail,*p;
head=tail=null;
int
i;
for(i=1;i<=n;i++)
{
p=(node
*)malloc(sizeof(node));
p->next=null;
printf("please
input
%d
score:",i);
scanf("%d",&p->score);
if(head==null)
head=tail=p;
else
{
tail->next=p;
tail=p;
}
}
return
head;
}
node
*range(node
*head)//排序
{
node
*p,*q;
int
score,i,n=0;
p=head;
while(p)
{
n++;
p=p->next;
}
for
(i=0;i
next!=null)//内循环
{
q=p->next;
if
(p->score>q->score)//值交换
{
score=p->score;
p->score=q->score;
q->score=score;
}
p=q;
}
}
return
head;
}
node
*connect(node
*head1,node
*head2)//合并
{
node
*p;
p=head1;
while(p->next!=null)
p=p->next;
p->next=head2;
return
head1;
}
void
output(node
*head)//输出
{
node
*p;
p=head;
while(p)
{
printf("%d
",p->score);
p=p->next;
}
printf("\n");
}
int
main()
{
node
*head,*hea1,*head2;
int
n1,n2;
printf("please
input
a
n1:");//第一个链表的成绩个数
scanf("%d",&n1);
hea1=create(n1);
printf("第一个链表的成绩:");
output(hea1);
printf("please
input
a
n2:");//第二个链表的成绩个数
scanf("%d",&n2);
head2=create(n2);
printf("第二个链表的成绩:");
output(head2);
head=connect(hea1,head2);
head=range(head);
printf("合并后,并排好序:");
output(head);
return
0;
}
温馨提示:内容为网友见解,仅供参考