该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
q2 = head2 = (struct y *)malloc(sizeof(struct y));
head2->c = c;
head2->next = p2;
p2 = q2;
}
}
}
out = dsx(head, head2); /*在dsx函数里面将head和head2链表释放*/
temp.a = out.a;
temp.b = out.b;
pushd(temp); /*将括号中的值压进单项式值栈*/
}
/*-----------------------------------------------------------------------------------------------------------------*/
/*----dsx.c---------------------------------------------------------------------------------------------------------*/
#include
#include
#include
struct k { /*定义单项式的结点, ax+b*/
double a; /* 含有变数字母x单项式的系数 */
double b; /* 常数项 */
struct k *next;
};
struct y { /*定义运算符号的结点*/
char c;
struct y *next;
};
int tong2(struct y *head2); /*对运算符号链表head2的'*'运算符号进行统计*/
struct k my(struct k one, struct k two, char n);
void seng(struct k *head, struct y *head2);
struct y *seng2(struct y *head2);
struct k dsx(struct k *head, struct y *head2) /*将多项式化为ax+b,返回ax+b*/
{
int f = 0;
struct k *p;
struct k temp;
struct y *p2;
/*--------------------------------------------------------------------------*/
/*对运算符号链表head2的'*'运算符号进行统计,tong2()等于或大于1时才执行下面2个函数*/
for (f = tong2(head2); 0
seng(head, head2);
head2 = seng2(head2);
}
/* 经以上处理后,运算符号链表中已经没有乘号,只剩下加号和减号*/
p = head; /*乘法运算后,乘数结点被删除后的单项式链表*/
p2 = head2; /*是乘号结点被删除后的运算符号链表*/
for (; p2 != NULL; p2 = p2->next) { /*定义结点ax+b,有一个好处就是相邻两个结点可以直接进行
加、减法运算*/
switch (p2->c) {
case '+' : temp = my(*p, *(p->next), '+');