0

write a program subtracting two polynomials using linked list

#include<stdio.h> #include<conio.h> struct node { int coeff, power; struct node *next; }; struct node *sub_poly(struct node *start1,struct node *start2,struct node *start3) { struct node *ptr1, *ptr2; int coeff, power; ptr1 = start1; ptr2 = start2; while(ptr1 != NULL && ptr2 != NULL) { if(ptr1 -> power == ptr2 -> power) { coeff = ptr1 -> coeff - ptr2 -> coeff; start3 = add_node(start3, coeff, ptr1 -> power) ptr1 = ptr1 -> next; ptr2 = ptr2 -> next; } else if(ptr1 -> power > ptr2 -> power) { start3 = add_node(start3, ptr1 -> coeff, ptr1 -> power) ptr1 = ptr1 -> next; } else if(ptr1 -> power < ptr2 -> power) { start3 = add_node(start3, -ptr2 -> coeff, ptr2 -> power) ptr2 = ptr2 -> next; } } if(ptr1 == NULL) { while(ptr2 != NULL) { start3 = add_node(start3, -ptr2

9th Aug 2020, 6:01 AM
ASWIN H
1 ответ