#include
#include
typedef struct splist
{
double data;
splist next;
} splist;
/单链表创建的思路
1.声明一个指针p和计数器变量i
2.初始化一个空链表L;
3.让L的头结点指针指向NULL,
4.循环;
生成一个新节点赋值给p
将p插入头结点和前一新节点之间
/
void CJ(splist *L,int n)
{
splist *p;
splist *x=L;
int i;
x=(splist)malloc(sizeof(splist));
x->next=NULL;
double c;
scanf("%lf",&c);
printf("请开始建表");
for(i=0;i
{
p=(splist*)malloc(sizeof(splist));
p->data=c;
p->next=x->next;
x->next=p;
}
}
double FH(splist*L,int i)
{
double *e;
int j;
splist*p;
splist *x=L;
p=x->next;
j=1;
while(p&&j
{
p=p->next;
j++;
}
if(!p||j>i)
return 0;
*e=p->data;
return *e;
}
int main()
{
splist *L;
double c;
int m;
int x;
printf("请输入表的长度");
scanf("%d",&m);
CJ(L,m);
printf("请输入要返回的序号");//运行时无法输入序号
scanf("%d",&x);
c=FH(L,x);
printf("%lf",c);
return 0;
}