#include <iostream>
using namespace Std;
Class poly{
Public
int Coef;
int expon;
Poly *next;
};
Poly*input (); /* Input Function */
Poly*attach (poly*rear, int c, int e); /* Link function, the result of the connection derivation */
Poly*func (Poly*head); /* function to implement derivation */
int main () {
Poly*p;
p = input ();
p = func (P);
while (p) {
cout << p->coef << "<< p->expon << (p->next==null? ') \ n ': ');
p = p->next;
}
return 0;
}
Poly*input () {
Poly*p = new Poly; /* Apply for new space */
Poly*head = p, *p1 = p;
while (Cin >> P->coef >> p->expon) {
char ch = getchar ();
P1 = p;
p = new Poly;
P1->next = p;
if (ch = = ' \ n ') */* Touch the newline key to jump */
Break
}
Delete p; /* Delete the empty node at the end */
P1->next = NULL;
return head; /* Return to head node */
}
Poly * Attach (poly*rear, int c, int e) {
Poly*p = new Poly; /* Insert First request space */
P->coef = C;
P->expon = e;
Rear->next = p;
Rear = P;
return rear; /* Returns the end pointer */
}
Poly*func (poly*p) {
Poly*head = new Poly; /* Apply for an empty node */
Poly*rear = head;
if (P->expon = = 0) {/* If only constant entries are processed separately */
P->coef = 0;
return p;
}
while (p&&p->expon) {/* The bounce condition is P is empty or P's exponent is O, for the derivation, the exponent is 0 can be omitted */
P->coef = p->coef*p->expon;
p->expon--;
Rear = Attach (rear, p->coef, p->expon);
p = p->next;
}
Rear->next = NULL; /* MOP up work */
Poly*temp = head;
Head = head->next; The head node moves to the next one.
Delete temp; To delete an empty head node
return head;
}
The derivation of polynomial