c语言程序综合设计cpp文件
1
#include
#include
#define LEN sizeof(struct node)
struct node
{
double num;
struct node * next;
};
int n1=0;
int n2=0;
int len = 0;
struct node * create_list(struct node * head,int n,int flag)
{
struct node * p1,* p2;
printf("请输入数列,以回车键结束一个数字的输入,以ctrl+z结束一数列的输入.\n");
p1 = p2 = (struct node *)malloc(LEN);
while(scanf("%lf",&p1->num) != EOF)
{
n++;
if(n==1) head = p1;
else p2->next = p1;
p2 = p1;
p1 = (struct node *)malloc(LEN);
}
p2->next = NULL;
free(p1);
if (flag == 1) n1 = n;
if (flag == 2) n2 = n;
return(head);
}
struct node * convert_list(struct node * head)
{
struct node * p1,* p2;
double t;
p1 = p2 = (struct node *)malloc(LEN);
p1 = p2 = head;
while(p1 != NULL)
{
p2 = p1->next;
while(p2 != NULL){
if(p1->num < p2->num){
t = p1->num;
p1->num = p2->num;
p2->num = t;
}
p2 = p2->next;
}
p1 = p1->next;
}
free(p1);free(p2);
return(head);
}
int main(){
struct node * head,* head1,* head2,* temp,* p,* p1,* p2;
head = head1 = head2 = temp = p = p1 = p2 = (struct node *)malloc(LEN);
head1 = create_list(head1,n1,1);
head2 = create_list(head2,n2,2);
head1 = convert_list(head1);
head2 = convert_list(head2);
temp = head1;
while(temp != NULL){
printf("%5.2f ",temp->num);
temp = temp->next;
}
printf("\n");
temp = head2;
while(temp != NULL){
printf("%5.2f ",temp->num);
temp = temp->next;
}
printf("\n");
p1 = head1; p2 = head2;
while( (n1 != 0) && (n2 != 0) ){
len++;
if(p1->num >= p2->num){
p->num = p1->num;
p1 = p1->next;
n1--;
}else {
p->num = p2->num;
p2 = p2->next;
n2--;
}
if(len==1) head = p;
else temp->next = p;
temp = p;
p = (struct node *)malloc(LEN);
}
if(n1 == 0) temp->next = p2;
if(n2 == 0) temp->next = p1;
temp = head;
while(temp != NULL){
printf("%5.2f ",temp->num);
temp = temp->next;
}
printf("\n");
free(head);free(head1);free(head2);free(temp);free(p);free(p1);free(p2);
return 0;
}
2
#include
#defin