假设给定 2 个多项式表达式,我正在尝试编写一个执行 3 种不同操作的程序:1.match(equality) 2.sum(addition) 和 3.dot(multiplication)。
class Node
{
public:
int coef;
int expo;
Node *next;
Node(int coef=0, int expo=0, Node *next=NULL)
{
this->coef = coef;
this->expo = expo;
this->next = next;
}
};
//
class LinkedList
{
public:
Node *head;
int size;
LinkedList()
{
head = new Node(0, 0, NULL);
head->coef = 0;
head->expo = 0;
head->next = NULL;
size = 0;
}
int degree();
int coefficient(int);
bool match(LinkedList *, LinkedList*);
void insert();
LinkedList sum(LinkedList *, LinkedList *);
LinkedList dot(LinkedList *, LinkedList *);
};LinkedList x, y, z;
我还定义了 memeber 函数,如下所示:
bool LinkedList::match(LinkedList *expr1, LinkedList *expr2)
{
// Check if both expressions have a same length
if (expr1->size != expr2->size)
{
cout << "The expressions do not match in length." << endl;
return false;
}
else if (expr1->size == expr2->size)
{
// Both expressions are the same in length, but not equal
while (expr1->head->coef && expr2->head->coef)
}
}
问题是我无法访问 expr1 和 expr2 内的节点,它们是指向 expr1 和 expr2 开头的指针有什么帮助吗?