数据结构综合实验报告_一元多项式(5)
时间:2025-03-10
时间:2025-03-10
while(c!=0) /*输入的第一项系数不允许为0,防止无意义的输入*/
{
s=(PotyNode *)malloc(sizeof(PotyNode));
s->coef=c;
s->expn=e;
s->next=NULL;
r->next=s; /*连接节点*/
r=s; /*指针r指向当前节点,用于连接下一节点*/
printf("\n系数与指数:");
scanf("%f%d",&c,&e);
}
return L;
}
/*获得指向第 i 个节点的指针,主要在删除节点的时候用来获得准备删除的前一节点*/
int Getlength(PotyNode *L)
{
PotyNode *p;
int count=0;
p=L->next;
while(p)
{
count++;
p=p->next ;
}
return count;
}
/*连表初始化及数据输入*/
PotyNode *GetElem_PotyNode(PotyNode *L,int i)
{
PotyNode *p;
int j=0;
p=L;
while(p->next&&j!=i) /*当p不是尾节点,并且不是第 i 个节点*/
{
j++;
p=p->next;
}
if(i==j)
return p; /*找到节点*/
上一篇:29 湖南武陵源风景名胜区