Dsa Polyinomial
Dsa Polyinomial
#define COMPARE(x, y) ( (x == y) ? 0 : (x > y) ? 1 : -1) head = attach(coef, xexp, yexp, zexp, head); } if(a->xexp!=0 || b->xexp!=0) {
int xexp, yexp, zexp; void display(NODE head) { case -1 : head3 = attach(b->coef, b->xexp, b->yexp, b->zexp, head3);
typedef struct node *NODE; if(head->link == head) { case 0 : if(a->yexp > b->yexp) {
NODE getnode() { printf("\nPolynomial does not exist."); head3 = attach(a->coef, a->xexp, a->yexp, a->zexp, head3);
if(x == NULL) { printf("%dx^%dy^%dz^%d", temp->coef, temp->xexp, temp->yexp, temp>zexp); head3 = attach(b->coef, b->xexp, b->yexp, b->zexp,
printf("Running out of memory \n"); temp = temp->link; if(temp != head) head3); b = b->link;break; }
NODE attach(int coef, int xexp, int yexp, int zexp, NODE head) { int poly_evaluate(NODE head) { head3 = attach(a->coef, a->xexp, a->yexp, a->zexp, head3);
NODE temp, cur; int x, y, z, sum = 0; a = a->link; break; } else if(a->zexp < b->zexp) {
temp = getnode(); NODE poly; head3 = attach(b->coef, b->xexp, b->yexp, b->zexp, head3);
temp->coef = coef; printf("\nEnter the value of x,y and z: "); b = b->link; break; }
temp->xexp = xexp; scanf("%d %d %d", &x, &y, &z); case 1 : head3 = attach(a->coef,a->xexp,a->yexp,a->zexp,head3);
cur = cur->link; } cur->link = temp; return sum; } case -1 : head3 = attach(b->coef, b->xexp, b->yexp, b->zexp, head3);
temp->link = head; return head; } NODE poly_sum(NODE head1, NODE head2, NODE head3) { b = b->link; break;
int i, j, coef, xexp, yexp, zexp, n; int coef; head3 = attach(a->coef, a->xexp, a->yexp, a->zexp, head3);
printf("\nEnter the no of terms in the polynomial: "); a = head1->link; a = a->link; break; }else if(a->zexp < b->zexp)
scanf("%d", &n); for(i=1; i<=n; i++) { b = head2->link; { head3 = attach(b->coef, b->xexp, b->yexp, b->zexp, head3);
printf("\n\tEnter the %d term: ",i); while(a!=head1 && b!=head2) {while(1) { b = b->link; break; }
printf("\n\t\tCoef = "); scanf("%d", &coef); if(a->xexp == b->xexp && a->yexp == b->yexp && a->zexp == b->zexp) { case 1 : head3 = attach(a->coef, a->xexp, a->yexp, a->zexp, head3);
printf("\n\t\tEnter Pow(x) Pow(y) and Pow(z): "); coef = a->coef + b->coef; a = a->link;break; } break; }
scanf("%d", &xexp); head3 = attach(coef, a->xexp, a->yexp, a->zexp, head3); if(a->zexp!=0 || b->zexp!=0) {
switch(COMPARE(a->zexp,b->zexp)) {
b = b->link; break;
while(b!= head2) {
head->link=head; head1->link=head1;
while(1) {
printf("\n~~~Menu~~~");
head = read_poly(head);
display(head1);