送分,下面两个简单的数据结构题,请提供C语言的算法!(100分)

  • 主题发起人 主题发起人 elton
  • 开始时间 开始时间
E

elton

Unregistered / Unconfirmed
GUEST, unregistred user!
问题1:
假设多项式:A19(x)=8+3x+9x10+5x17+7x19,写出算法实现!
问题2:
求算式 A*(B+C/D)-E*F+G 的前缀表达式和后缀表达式。
尽快,今天必要完成哦,呵呵!
 
问题很难吗?
怎么没有高手呢?
 
这是delphi不是C语言
呵呵
 
問題不難。
不難的問題就快不起來了。
 
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
/*
问题1:假设多项式:A19(x)=8+3x+9x10+5x17+7x19,写出算法实现!
*/
struct node{
float index;
float coef;
struct node *link;
};
typedef struct node NODE;
NODE *create(void)
{NODE *newnode,*head,*p;
float index,coef;
head=(NODE *)malloc(sizeof(NODE));
head->link=NULL;
p=head;
printf("/n输入多项式的系数和指数,以0,0结束:");
scanf("%f,%f",&amp;index,&amp;coef);
while((index!=0)&amp;&amp;(coef!=0))
{newnode=(NODE *)malloc(sizeof(NODE));
newnode->index=index;
newnode->coef =coef;
newnode->link=NULL;
p->link =newnode;
p=p->link;
printf("/n输入下一项:");
scanf("%f,%f",&amp;index,&amp;coef);
}
return head;
}
/*根据给定的表达式和x的值,此函数计算出最后的表达式的值*/
float fun(NODE *head,float x)
{
float sum=0;
NODE *p=head->link;
while(p!=NULL)
{
sum+=p->index*pow(x,p->coef);
p=p->link;
}
return sum;
}
int main( )
{
NODE *head;
float x;
head=create();
printf("/n请输入x的值:");
scanf("%f",&amp;x);
printf("/n最后结果为A19(%.0f)=%.f.",x,fun(head,x));
getch();
}
/*该程序在Tc,C++builder下调试通过*/
//---------------------------------------------------------------------------
 
前缀:+-*A+B/CD*EFG
后缀:ABCD/+*EF*-G+
 
多人接受答案了。
 
后退
顶部