Linked List Applications
Linked List Applications
h>
#include <stdlib.h>
float coefficient;
int exponent;
} Term;
newTerm->coefficient = coeff;
newTerm->exponent = exp;
newTerm->next = NULL;
if (*poly == NULL) {
*poly = newTerm;
} else {
temp = temp->next;
temp->next = newTerm;
temp = temp->next;
if (temp != NULL) {
printf(" + ");
}
}
printf("\n");
poly1 = poly1->next;
poly2 = poly2->next;
} else {
poly1 = poly1->next;
poly2 = poly2->next;
poly1 = poly1->next;
poly2 = poly2->next;
return result;
poly1 = poly1->next;
poly2 = poly2->next;
} else {
poly1 = poly1->next;
poly2 = poly2->next;
poly1 = poly1->next;
poly2 = poly2->next;
return result;
temp2 = temp2->next;
temp1 = temp1->next;
return result;
if (temp->exponent != 0) {
temp = temp->next;
return result;
10
Term* temp;
temp = poly;
poly = poly->next;
free(temp);
Term* inputPolynomial() {
int numTerms,i;
float coeff;
int exp;
return poly;
int main() {
int choice;
11
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Derivation\n");
scanf("%d", &choice);
poly1 = inputPolynomial();
if (choice != 4) {
poly2 = inputPolynomial();
switch (choice) {
case 1:
break;
case 2:
displayPolynomial(subtractPolynomials(poly1, poly2));
break;
case 3:
displayPolynomial(multiplyPolynomials(poly1, poly2));
break;
case 4:
12
displayPolynomial(derivePolynomial(poly1));
break;
default:
printf("Invalid choice\n");
freePolynomial(poly1);
freePolynomial(poly2);
return 0;