1999年下午高程的一道考题,谁能给解释一下阿
1999年下午第五题
【程序5说明】
本程序实现两个多项式相乘。多项式用链表表示,链表上的各表元按多项式的幂指数降序链接。例如:
f(x)=5.7x15+4.8x6+9.65
设两个多项式f(x)和g(x)分别为
f(x)=fnxn+ ... +f1x+f0 g(x)=gmxm+ ... +g1x+g0
其积多项式为 s(x)=f(x)g(x)=skxk+ ... +s1x+s0
其中 k=n+m , si= (0≤i≤k)
#include <stdio.h>
#include <malloc.h>
typedef struct elem { int index; double coef; struct elem *next;
} POLYNODE;
//这段程序中
有一个变量u
按照答案来看
只有赋值项
没有取出来
想请问这段程序中
u的作用
POLYNODE * inpoly()
{ POLYNODE *u, *v, *h = NULL, *p; int index; double coef;
printf(“Input index(<0 for finish) “); scanf(“%d”, &index);
while (index >=0 ) {
printf(“Input coef “); scanf (“%1f”, &coef);
p = (POLYNODE *)malloc(sizeof(POLYNODE));
p->index = index; p->coef = coef;
v = h ;
while (v != NULL && index < v->index) { u = v; v = v->next;}
if (v == NULL || index > v->index)
{ p->next = v; if (v == h ) ____h=p____; else ____u->next=p____;}
else v->coef += coef;
printf(“Input index(<0 for finish) “); scanf(“%d”, &index);
}
return h;
}
//这段程序中
有一个变量u
按照答案来看
只有赋值项
没有取出来
想请问这段程序中
u的作用