用指针构造链表,操作链表

来源:百度知道 编辑:UC知道 时间:2024/05/16 20:38:03
实验目的:
学习用指针构造链表,操作链表
实验内容:
输入两个非降序列,转换成两个非升序列,合并成一个非升序列。
基本要求:
用链表实现。

#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct xulie)
struct xulie
{ double num;
struct xulie *next;
} ;

struct xulie *creat(int n)
{ struct xulie *head,*p1,*p2;
char a;
p1=p2=(struct xulie*)malloc(LEN);
printf("please input these number\n");
scanf("%f",&p1->num);
head=NULL;
while(a!='a')
{ n=n+1;
if(n==1)head=p1;
else {p2->next=p1;p2=p2->next;p1=(struct xulie*)malloc(LEN);}
scanf("%f",&p1->num);
a=getchar();
}
p2->next=NULL;
free (p1);free(p2);
printf("建立一个了%d位数的数列",n);
return (head);

}

struct xulie *change(struct xulie *head)
{struct xulie *p1,*p2;
double t;
p1=p2=(struct xulie *)malloc(LEN);
p1=p2=head;
while(p1!=N