So schreibe ich ein Programm, das aus Multiplikationsfunktion Implementierungen besteht, habe jedoch Probleme beim Schreiben von 3 Funktionen: übereinstimmen, hinzufügen und multiplizieren.Match, Addieren und Multiplikation für Polynome mit verknüpften Liste
Die Match-Funktion soll anzeigen, ob 2 Polynome gleich sind. wenn das der Fall ist, ist es wahr, sonst falsch.
Add-Funktion jut fügt 2 Polynome hinzu.
Multiplikation produziert nur das Produkt von 2 Polynomen.
Ich bin fest, wie diese Funktionen beginnen. Jeder Rat oder jede Rückmeldung wird hilfreich sein. Ich danke dir sehr.
class Dlist
{
private:
Node* front;
public:
Dlist(Node* f = NULL){front = f;}
void insertInOrder(int c, int x, int y)
{
Node* nn = new Node;
nn->coef = c;
nn->xdeg = x;
nn->ydeg = y;
int nsum = x + y;
Node* p = front;
if(front == NULL){
front = nn;
return;
}
while(p != NULL){
if(x == p->xdeg && y == p->ydeg){
p->coef += c;
return;
}
p = p->next;
}
p = front;
if(nsum > p->xdeg + p->ydeg){
nn->next = p;
front = nn;
return;
}
else{
while(p->next != NULL && p->next->xdeg + p->next->ydeg > nsum){
p = p->next;
}
}
nn->next = p->next;
p->next = nn;
return;
};
void print()
{
Node* p = front;
while(p != NULL){
cout << p->coef << "/" << p->xdeg << "/" << p->ydeg << " -> ";
p = p->next;
}
cout << "NULL" << endl;
return;
};
int degree()
{
Node* p = front;
int maxd = 0;
while(p != NULL){
if(maxd < p->xdeg + p->ydeg){
maxd = p->xdeg + p->ydeg;
}
p = p->next;
}
return maxd;
};
void coefficient(int input)
{
Node* p = front;
int index = 0;
while(p != NULL){
p = p->next;
index++;
}
if(input < 0){
cout << "Does not exist." << endl;
return;
}
else if(input > index){
cout << "Does not exist." << endl;
return;
}
p = front;
for(int i = 0; i != input; i++){
p = p->next;
}
cout << p->coef << endl;
return;
}
void sum()
{
}
};
Polynome als 'std :: vector' darstellen Dinge erleichtern (Randnotiz: Rechnen mit Polynomen wird sehr bald ungenau) –