作业帮 > 综合 > 作业

用循环链表表示一元多项式f(x)请给出该链表节点结构的定义,并编写一个函数value(x),

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 09:44:23
用循环链表表示一元多项式f(x)请给出该链表节点结构的定义,并编写一个函数value(x),
计算多项式在x=x0处的值
#include
#include "stdlib.h"
#include
// 结点的结构
typedef struct node
{
int xishu;
int zhishu;
struct node *next;
} ListNode;
//新建链表
ListNode* CreateList()
{
ListNode *head ,*node1 ,*node2;
int xi,zhi;
head = node1 = node2 = NULL;
//读输入的数据,新建链表
cin >> xi;
cin >> zhi;
while (xi !=0 || zhi != 0)//以系数为0,指数为0作为结束条件
{
node2 = (ListNode*)malloc(sizeof(ListNode));
node2->next = NULL;
node2->xishu = xi;
node2->zhishu = zhi;
if (head == NULL)
head = node2;
else
node1->next = node2;
node1 = node2;
cin >> xi;
cin >> zhi;
}
return head;;
}
//链表输出
void ReadList(ListNode *head)
{
ListNode *node1;
node1 = head;
while(node1)
{
cout xishu xishu * pow(x0 ,node1->zhishu);
node1 = node1->next;
}
return total;
}
void main()
{
ListNode *head;
int x0 ,result;
head = CreateList();
ReadList(head);
cout > x0;
result = Calc(head ,x0);
cout