c语言程序.cpp文件,c语言程序综合设计cpp文件.doc

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值