哈工大威海数据结构实验一 线性结构
一元多项式的求导
直接放代码
#include <iostream>
using namespace std;
typedef struct Function{
int coef ;
int index ;
struct Function * next;
}Data ;
class List{
public:
Data* CreatData(int coef,int index){
Data * head;
head=new Data;
head->coef=coef;
head->index=index;
head->next=NULL;
return head;
}
void InsertData(Data* head){
Data*p,*t;
p=head;
int temp;
int coef,index;
do
{
scanf("%d",&temp);
coef=temp;
scanf("%d",&temp);
index=temp;
t=CreatData(coef,index);
p->next=t;
p=p->next;
} while (temp=getchar()!='\n');
}
void Derivative(Data* head){
Data* p;
p=head->next;
while(p!=NULL)
{
if(head->next->index==0&&head->next->next==NULL){
cout<<0<<" "<<0;
}
else if(p->index==0){
}
else{
cout<<p->coef*p->index<<" "<<p->index-1<<" ";
}
p=p->next;
}
}
};
int main(){
List list ;
Data* head=list.CreatData(0,0);
list.InsertData(head);
list.Derivative(head);
system("pause");
}