Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理目录后的作业 #18

Merged
merged 10 commits into from
May 17, 2017
68 changes: 68 additions & 0 deletions 2017-1/zjc/10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<stdio.h>
#include<stdlib.h>
struct list{
int data;
struct list *next;
};
void input(struct list *head,int number)
{
printf("������Ӧ��������\n");
int i;
struct list *temp;
struct list *end;
end=head;
for(i=0;i!=number;i++)
{
temp=(struct list *)malloc(sizeof(struct list));
scanf("%d",&temp->data);
end->next=temp;
temp->next=NULL;
end=temp;
}
}
void sort(struct list *l1,struct list *l2)
{
struct list *p1,*p2,*temp;
p1=l1;
p2=l2->next;
while(p1->next&&p2)
{
if(p1->next->data>p2->data)
{
temp=p2->next;
p2->next=p1->next;
p1->next=p2;
p2=temp;
}
else
p1=p1->next;
}
if(p2)
p1->next=p2;
}
void output(struct list *head)
{
printf("���Lc��\n");
while(head->next)
{
printf("%d ",head->next->data);
head=head->next;
}
}
int main()
{
int num;
list *h1,*h2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h1=(struct list*)malloc(sizeof(struct list));
h2=(struct list*)malloc(sizeof(struct list));
h1->next=NULL;
h2->next=NULL;
printf("����La�ij��ȣ�\n");
scanf("%d",&num);
input(h1,num);
printf("����Lb�ij���:\n");
scanf("%d",&num);
input(h2,num);
sort(h1,h2);
output(h1);
}