Use the following typedefs: typedef struct {double dCoeff;//coefficient int iExp
ID: 3937211 • Letter: U
Question
Use the following typedefs: typedef struct {double dCoeff;//coefficient int iExponent;//exponent} PolyTerm; typedef struct Node {PolyTerm term; struct Node *pNext;} Node; Provide working code using linked lists (with pointers) which includes these functions: printPolynomial(Node *pPolyHead) prints a polynomial (represented by a linked list) in a manner that clearly shows the coefficient and exponent for each term. Node *addPolynomials(Node *pPolyAHead. Node *pPolyBhead) returns a pointer to a new polynomial (represented by a linked list) which is the result of adding two polynomials. Your code should work for the following linked lists: Adding A = 3x^6 + 2x^3 + 1 B = 8x^14 - 3x^6 + 10x^4 + 5X^3 Would give us this answer Your code should work for any polynomials. Extra Credit Points 10 + 100/n where n is the number of people who submitted completely correct solutions. Late work is not accepted. What to Turn In A zip file named ExtraLastNameFirstName containing: Any .h file you created Any .c file you created Your output for the example above. Please do not submit code that is not working since it is worth 0 points. How can I create a zip file containing several files in Linux? As a command, type: zip -r zipFileName.zipfileName1 filename2...Explanation / Answer
#include<stdio.h>
#include<conio.h>
createPolynomial(Node *pPolyHead)
printPolynomial(Node *pPolyHead);
Node *addPolynomials(Node *pPolyAHead, Node *pPolyBHead, Node *pPolyCHeadHead)
;
void main()
{
clrscr();
PolyAHead=PolyBHead=PolyCHead=NULL;
PolyAHead=(struct list*)malloc(sizeof(struct list));
PolyBHead=(struct list*)malloc(sizeof(struct list));
PolyCHead=(struct list*)malloc(sizeof(struct list));
printf("Enter the first polynomial: ");
createPolynomial(PolyAHead);
printf("Enter the second polynomial: ");
createPolynomial(PolyBHead);
printf("Addition of two polynomial: ");
polyadd(PolyAHead,PolyBHead,PolyCHead);
printf("first polynomial ");
printPolynomial(PolyAHead);
printf(" second polynomial ");
printPolynomial(PolyBHead);
printf(" printf the polynomial: ");
printPolynomial(PolyCHead);
getch();
}
createPolynomial(struct list *n_node)
{
char ch;
int c,p;
do{
printf("Enter the coeffiecient and power: ");
scanf("%d%d",&c,&p);
n_node->coeff=c;
n_node->pow=p;
n_node->next=(struct list*)malloc(sizeof(struct list));
n_node=n_node->next;
n_node->next=NULL;
printf("Continue ");
ch=getch();
}while(ch=='y' || ch=='Y');
}
printPolynomial(struct list *node)
<em id="__mceDel"> {
while(node->next!=NULL)
{
printf("%dx^%d",node->coeff,node->pow);</em>
if(node->coeff>0)
printf("+");
else
printf("-");
node=node->next;
}
}
Node *addPolynomials(Node *pPolyAHead, Node *pPolyBHead, Node *pPolyCHeadHead){
while(PolyAHead->next && PolyBHead->next)
{
if(PolyAHead->pow>PolyBHead->pow)
{
PolyCHead->coeff=PolyAHead->coeff;
PolyCHead->pow=PolyAHead->pow;
PolyAHead=PolyAHead->next;
}
else if(PolyBHead->pow>PolyAHead->pow)
{
PolyCHead->coeff=PolyBHead->coeff;
PolyCHead->pow=PolyBHead->pow;
PolyBHead=PolyBHead->next;
}
else
{
PolyCHead->coeff=PolyAHead->coeff+PolyBHead->coeff;
PolyCHead->pow=PolyAHead->pow;
PolyAHead=PolyAHead->next;
PolyBHead=PolyBHead->next;
}</em>
PolyCHead->next=(struct list*)malloc(sizeof(struct list));
PolyCHead=PolyCHead->next;
PolyCHead->next=NULL;
}
while(PolyAHead->next ||PolyBHead->next)
{
if(PolyAHead->next)
{
PolyCHead->coeff=PolyAHead->coeff;
PolyCHead->pow=PolyAHead->pow;
PolyAHead=PolyAHead->next;
}
if(PolyBHead->next)
{
PolyCHead->coeff=PolyBHead->coeff;
PolyCHead->pow=PolyBHead->pow;
PolyBHead=PolyBHead->next;
}
PolyCHead->next=(struct list*)malloc(sizeof(struct list));
PolyCHead=PolyCHead->next;
PolyCHead->next=NULL;
}
}
#include<stdio.h>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.