The derivation of polynomial

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.